http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/core/src/main/java/org/apache/accumulo/core/util/Encoding.java ---------------------------------------------------------------------- diff --cc core/src/main/java/org/apache/accumulo/core/util/Encoding.java index 761fc1f,b26b363..259f783 --- a/core/src/main/java/org/apache/accumulo/core/util/Encoding.java +++ b/core/src/main/java/org/apache/accumulo/core/util/Encoding.java @@@ -16,7 -16,7 +16,7 @@@ */ package org.apache.accumulo.core.util; - import java.nio.charset.StandardCharsets; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; import org.apache.accumulo.core.util.Base64; import org.apache.hadoop.io.Text;
http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/core/src/main/java/org/apache/accumulo/core/util/FastFormat.java ---------------------------------------------------------------------- diff --cc core/src/main/java/org/apache/accumulo/core/util/FastFormat.java index 7b84dc8,d1994ce..e103ac6 --- a/core/src/main/java/org/apache/accumulo/core/util/FastFormat.java +++ b/core/src/main/java/org/apache/accumulo/core/util/FastFormat.java @@@ -16,7 -16,7 +16,7 @@@ */ package org.apache.accumulo.core.util; - import java.nio.charset.StandardCharsets; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; public class FastFormat { // this 7 to 8 times faster than String.format("%s%06d",prefix, num) http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/core/src/main/java/org/apache/accumulo/core/util/Merge.java ---------------------------------------------------------------------- diff --cc core/src/main/java/org/apache/accumulo/core/util/Merge.java index 167933f,05067b5..c156311 --- a/core/src/main/java/org/apache/accumulo/core/util/Merge.java +++ b/core/src/main/java/org/apache/accumulo/core/util/Merge.java @@@ -16,7 -16,8 +16,8 @@@ */ package org.apache.accumulo.core.util; - import java.nio.charset.StandardCharsets; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; + import java.util.ArrayList; import java.util.Iterator; import java.util.List; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/core/src/main/java/org/apache/accumulo/core/util/MonitorUtil.java ---------------------------------------------------------------------- diff --cc core/src/main/java/org/apache/accumulo/core/util/MonitorUtil.java index 90268ef,e71a377..4a0f9ef --- a/core/src/main/java/org/apache/accumulo/core/util/MonitorUtil.java +++ b/core/src/main/java/org/apache/accumulo/core/util/MonitorUtil.java @@@ -16,7 -16,7 +16,7 @@@ */ package org.apache.accumulo.core.util; - import java.nio.charset.StandardCharsets; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.client.Instance; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/core/src/main/java/org/apache/accumulo/core/util/TextUtil.java ---------------------------------------------------------------------- diff --cc core/src/main/java/org/apache/accumulo/core/util/TextUtil.java index a57839b,617c079..66ad8f5 --- a/core/src/main/java/org/apache/accumulo/core/util/TextUtil.java +++ b/core/src/main/java/org/apache/accumulo/core/util/TextUtil.java @@@ -16,9 -16,10 +16,9 @@@ */ package org.apache.accumulo.core.util; - import java.nio.ByteBuffer; - import java.nio.charset.StandardCharsets; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; + import java.nio.ByteBuffer; - import org.apache.accumulo.core.Constants; import org.apache.hadoop.io.Text; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/core/src/test/java/org/apache/accumulo/core/client/BatchWriterConfigTest.java ---------------------------------------------------------------------- diff --cc core/src/test/java/org/apache/accumulo/core/client/BatchWriterConfigTest.java index 8f0812c,c276056..a386c04 --- a/core/src/test/java/org/apache/accumulo/core/client/BatchWriterConfigTest.java +++ b/core/src/test/java/org/apache/accumulo/core/client/BatchWriterConfigTest.java @@@ -16,6 -16,7 +16,7 @@@ */ package org.apache.accumulo.core.client; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; @@@ -161,14 -155,8 +161,14 @@@ public class BatchWriterConfigTest bwConfig.setMaxWriteThreads(24); bwConfig.setTimeout(3, TimeUnit.SECONDS); bytes = createBytes(bwConfig); - assertEquals(" v#maxWriteThreads=24,timeout=3000", new String(bytes, StandardCharsets.UTF_8)); + assertEquals(" v#maxWriteThreads=24,timeout=3000", new String(bytes, UTF_8)); checkBytes(bwConfig, bytes); + + // test human-readable durability + bwConfig = new BatchWriterConfig(); + bwConfig.setDurability(Durability.LOG); + bytes = createBytes(bwConfig); - assertEquals(" e#durability=LOG", new String(bytes, StandardCharsets.UTF_8)); ++ assertEquals(" e#durability=LOG", new String(bytes, UTF_8)); } @Test http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/core/src/test/java/org/apache/accumulo/core/client/ZooKeeperInstanceTest.java ---------------------------------------------------------------------- diff --cc core/src/test/java/org/apache/accumulo/core/client/ZooKeeperInstanceTest.java index 98de0b5,dce742f..5d0b604 --- a/core/src/test/java/org/apache/accumulo/core/client/ZooKeeperInstanceTest.java +++ b/core/src/test/java/org/apache/accumulo/core/client/ZooKeeperInstanceTest.java @@@ -16,6 -16,7 +16,7 @@@ */ package org.apache.accumulo.core.client; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/core/src/test/java/org/apache/accumulo/core/client/mock/MockNamespacesTest.java ---------------------------------------------------------------------- diff --cc core/src/test/java/org/apache/accumulo/core/client/mock/MockNamespacesTest.java index 1e86f73,e2661e2..b45054a --- a/core/src/test/java/org/apache/accumulo/core/client/mock/MockNamespacesTest.java +++ b/core/src/test/java/org/apache/accumulo/core/client/mock/MockNamespacesTest.java @@@ -17,6 -17,7 +17,7 @@@ package org.apache.accumulo.core.client.mock; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/core/src/test/java/org/apache/accumulo/core/client/security/tokens/CredentialProviderTokenTest.java ---------------------------------------------------------------------- diff --cc core/src/test/java/org/apache/accumulo/core/client/security/tokens/CredentialProviderTokenTest.java index 46607ea,7bb3fa4..bbed50c --- a/core/src/test/java/org/apache/accumulo/core/client/security/tokens/CredentialProviderTokenTest.java +++ b/core/src/test/java/org/apache/accumulo/core/client/security/tokens/CredentialProviderTokenTest.java @@@ -16,11 -16,12 +16,11 @@@ */ package org.apache.accumulo.core.client.security.tokens; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.File; import java.io.IOException; import java.net.URL; - import java.nio.charset.StandardCharsets; -- import org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties; import org.apache.accumulo.core.conf.CredentialProviderFactoryShim; import org.junit.Assert; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/core/src/test/java/org/apache/accumulo/core/client/security/tokens/PasswordTokenTest.java ---------------------------------------------------------------------- diff --cc core/src/test/java/org/apache/accumulo/core/client/security/tokens/PasswordTokenTest.java index a3ce8d4,878b5e0..3751f02 --- a/core/src/test/java/org/apache/accumulo/core/client/security/tokens/PasswordTokenTest.java +++ b/core/src/test/java/org/apache/accumulo/core/client/security/tokens/PasswordTokenTest.java @@@ -16,7 -16,7 +16,7 @@@ */ package org.apache.accumulo.core.client.security.tokens; - import java.nio.charset.StandardCharsets; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; import javax.security.auth.DestroyFailedException; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/core/src/test/java/org/apache/accumulo/core/data/ConditionTest.java ---------------------------------------------------------------------- diff --cc core/src/test/java/org/apache/accumulo/core/data/ConditionTest.java index 8672836,d9a47d7..c76275b --- a/core/src/test/java/org/apache/accumulo/core/data/ConditionTest.java +++ b/core/src/test/java/org/apache/accumulo/core/data/ConditionTest.java @@@ -16,6 -16,7 +16,7 @@@ */ package org.apache.accumulo.core.data; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/core/src/test/java/org/apache/accumulo/core/data/ConditionalMutationTest.java ---------------------------------------------------------------------- diff --cc core/src/test/java/org/apache/accumulo/core/data/ConditionalMutationTest.java index 591baaa,908c391..4326227 --- a/core/src/test/java/org/apache/accumulo/core/data/ConditionalMutationTest.java +++ b/core/src/test/java/org/apache/accumulo/core/data/ConditionalMutationTest.java @@@ -16,6 -16,7 +16,7 @@@ */ package org.apache.accumulo.core.data; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/core/src/test/java/org/apache/accumulo/core/data/ValueTest.java ---------------------------------------------------------------------- diff --cc core/src/test/java/org/apache/accumulo/core/data/ValueTest.java index cd26743,8022c14..0aa7649 --- a/core/src/test/java/org/apache/accumulo/core/data/ValueTest.java +++ b/core/src/test/java/org/apache/accumulo/core/data/ValueTest.java @@@ -17,6 -17,8 +17,8 @@@ */ package org.apache.accumulo.core.data; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/core/src/test/java/org/apache/accumulo/core/iterators/user/RegExFilterTest.java ---------------------------------------------------------------------- diff --cc core/src/test/java/org/apache/accumulo/core/iterators/user/RegExFilterTest.java index ec516d0,d8179df..2649f90 --- a/core/src/test/java/org/apache/accumulo/core/iterators/user/RegExFilterTest.java +++ b/core/src/test/java/org/apache/accumulo/core/iterators/user/RegExFilterTest.java @@@ -16,8 -16,9 +16,9 @@@ */ package org.apache.accumulo.core.iterators.user; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.IOException; - import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.TreeMap; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/core/src/test/java/org/apache/accumulo/core/security/ColumnVisibilityTest.java ---------------------------------------------------------------------- diff --cc core/src/test/java/org/apache/accumulo/core/security/ColumnVisibilityTest.java index cf91cb0,2577e48..1a46004 --- a/core/src/test/java/org/apache/accumulo/core/security/ColumnVisibilityTest.java +++ b/core/src/test/java/org/apache/accumulo/core/security/ColumnVisibilityTest.java @@@ -16,6 -16,7 +16,7 @@@ */ package org.apache.accumulo.core.security; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; import static org.apache.accumulo.core.security.ColumnVisibility.quote; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/core/src/test/java/org/apache/accumulo/core/security/CredentialsTest.java ---------------------------------------------------------------------- diff --cc core/src/test/java/org/apache/accumulo/core/security/CredentialsTest.java index 5ecfdfb,a4e9f02..c5746bc --- a/core/src/test/java/org/apache/accumulo/core/security/CredentialsTest.java +++ b/core/src/test/java/org/apache/accumulo/core/security/CredentialsTest.java @@@ -16,6 -16,7 +16,7 @@@ */ package org.apache.accumulo.core.security; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/core/src/test/java/org/apache/accumulo/core/security/VisibilityConstraintTest.java ---------------------------------------------------------------------- diff --cc core/src/test/java/org/apache/accumulo/core/security/VisibilityConstraintTest.java index d8bff67,523279a..c9aa5d2 --- a/core/src/test/java/org/apache/accumulo/core/security/VisibilityConstraintTest.java +++ b/core/src/test/java/org/apache/accumulo/core/security/VisibilityConstraintTest.java @@@ -16,6 -16,7 +16,7 @@@ */ package org.apache.accumulo.core.security; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.createNiceMock; import static org.easymock.EasyMock.expect; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/core/src/test/java/org/apache/accumulo/core/security/crypto/BlockedIOStreamTest.java ---------------------------------------------------------------------- diff --cc core/src/test/java/org/apache/accumulo/core/security/crypto/BlockedIOStreamTest.java index d80124c,9078ef9..0774849 --- a/core/src/test/java/org/apache/accumulo/core/security/crypto/BlockedIOStreamTest.java +++ b/core/src/test/java/org/apache/accumulo/core/security/crypto/BlockedIOStreamTest.java @@@ -16,6 -16,7 +16,7 @@@ */ package org.apache.accumulo.core.security.crypto; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/core/src/test/java/org/apache/accumulo/core/util/format/ShardedTableDistributionFormatterTest.java ---------------------------------------------------------------------- diff --cc core/src/test/java/org/apache/accumulo/core/util/format/ShardedTableDistributionFormatterTest.java index 8f46c89,eef06c3..e8879a5 --- a/core/src/test/java/org/apache/accumulo/core/util/format/ShardedTableDistributionFormatterTest.java +++ b/core/src/test/java/org/apache/accumulo/core/util/format/ShardedTableDistributionFormatterTest.java @@@ -16,6 -16,7 +16,7 @@@ */ package org.apache.accumulo.core.util.format; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/fate/src/main/java/org/apache/accumulo/fate/AdminUtil.java ---------------------------------------------------------------------- diff --cc fate/src/main/java/org/apache/accumulo/fate/AdminUtil.java index 8884cd9,af31cf2..60ff4b4 --- a/fate/src/main/java/org/apache/accumulo/fate/AdminUtil.java +++ b/fate/src/main/java/org/apache/accumulo/fate/AdminUtil.java @@@ -16,7 -16,8 +16,8 @@@ */ package org.apache.accumulo.fate; - import java.nio.charset.Charset; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; + import java.util.ArrayList; import java.util.Collections; import java.util.EnumSet; @@@ -38,8 -38,6 +39,7 @@@ import org.apache.zookeeper.KeeperExcep * A utility to administer FATE operations */ public class AdminUtil<T> { - private static final Charset UTF8 = Charset.forName("UTF-8"); + private static final Logger log = Logger.getLogger(AdminUtil.class); private boolean exitOnError = false; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/fate/src/main/java/org/apache/accumulo/fate/ZooStore.java ---------------------------------------------------------------------- diff --cc fate/src/main/java/org/apache/accumulo/fate/ZooStore.java index 5fc1858,34e0235..0dc156e --- a/fate/src/main/java/org/apache/accumulo/fate/ZooStore.java +++ b/fate/src/main/java/org/apache/accumulo/fate/ZooStore.java @@@ -16,6 -16,8 +16,8 @@@ */ package org.apache.accumulo.fate; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/fate/src/main/java/org/apache/accumulo/fate/zookeeper/DistributedReadWriteLock.java ---------------------------------------------------------------------- diff --cc fate/src/main/java/org/apache/accumulo/fate/zookeeper/DistributedReadWriteLock.java index ea7f02c,b2e263a..d10fcd2 --- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/DistributedReadWriteLock.java +++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/DistributedReadWriteLock.java @@@ -16,7 -16,8 +16,8 @@@ */ package org.apache.accumulo.fate.zookeeper; - import java.nio.charset.Charset; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; + import java.util.Arrays; import java.util.Iterator; import java.util.Map.Entry; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCache.java ---------------------------------------------------------------------- diff --cc fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCache.java index 74c525e,4907bc6..ee53ddd --- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCache.java +++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCache.java @@@ -16,6 -16,8 +16,8 @@@ */ package org.apache.accumulo.fate.zookeeper; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java ---------------------------------------------------------------------- diff --cc fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java index 5fef905,f61c214..1391d98 --- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java +++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java @@@ -16,7 -16,8 +16,8 @@@ */ package org.apache.accumulo.fate.zookeeper; - import java.nio.charset.Charset; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; + import java.util.ArrayList; import java.util.Collections; import java.util.List; @@@ -33,8 -34,7 +34,7 @@@ import org.apache.zookeeper.ZooKeeper import org.apache.zookeeper.data.Stat; public class ZooLock implements Watcher { - private static final Charset UTF8 = Charset.forName("UTF-8"); - protected static final Logger log = Logger.getLogger(ZooLock.class); + private static final Logger log = Logger.getLogger(ZooLock.class); public static final String LOCK_PREFIX = "zlock-"; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReservation.java ---------------------------------------------------------------------- diff --cc fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReservation.java index ea7f4b9,2e2acc3..f1ba428 --- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReservation.java +++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReservation.java @@@ -16,7 -16,7 +16,7 @@@ */ package org.apache.accumulo.fate.zookeeper; - import java.nio.charset.Charset; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; import org.apache.accumulo.fate.zookeeper.ZooUtil.NodeExistsPolicy; import org.apache.accumulo.fate.zookeeper.ZooUtil.NodeMissingPolicy; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java ---------------------------------------------------------------------- diff --cc fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java index b6890c6,ff35364..0059af7 --- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java +++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java @@@ -16,9 -16,10 +16,10 @@@ */ package org.apache.accumulo.fate.zookeeper; -import static com.google.common.base.Charsets.UTF_8; ++import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.IOException; import java.net.UnknownHostException; - import java.nio.charset.Charset; import java.util.HashMap; import java.util.Map; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/mapreduce/src/main/java/org/apache/accumulo/core/client/mapreduce/RangeInputSplit.java ---------------------------------------------------------------------- diff --cc mapreduce/src/main/java/org/apache/accumulo/core/client/mapreduce/RangeInputSplit.java index b591a68,0000000..29cf95d mode 100644,000000..100644 --- a/mapreduce/src/main/java/org/apache/accumulo/core/client/mapreduce/RangeInputSplit.java +++ b/mapreduce/src/main/java/org/apache/accumulo/core/client/mapreduce/RangeInputSplit.java @@@ -1,522 -1,0 +1,523 @@@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.accumulo.core.client.mapreduce; + ++import static java.nio.charset.StandardCharsets.UTF_8; ++ +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.math.BigInteger; - import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.accumulo.core.client.ClientConfiguration; +import org.apache.accumulo.core.client.Instance; +import org.apache.accumulo.core.client.IteratorSetting; +import org.apache.accumulo.core.client.ZooKeeperInstance; +import org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator; +import org.apache.accumulo.core.client.mapreduce.lib.impl.ConfiguratorBase.TokenSource; +import org.apache.accumulo.core.client.mock.MockInstance; +import org.apache.accumulo.core.client.security.tokens.AuthenticationToken; +import org.apache.accumulo.core.client.security.tokens.AuthenticationToken.AuthenticationTokenSerializer; +import org.apache.accumulo.core.data.ByteSequence; +import org.apache.accumulo.core.data.Key; +import org.apache.accumulo.core.data.PartialKey; +import org.apache.accumulo.core.data.Range; +import org.apache.accumulo.core.security.Authorizations; +import org.apache.accumulo.core.util.Base64; +import org.apache.accumulo.core.util.Pair; +import org.apache.hadoop.io.Text; +import org.apache.hadoop.io.Writable; +import org.apache.hadoop.mapreduce.InputSplit; +import org.apache.log4j.Level; + +/** + * The Class RangeInputSplit. Encapsulates an Accumulo range for use in Map Reduce jobs. + */ +public class RangeInputSplit extends InputSplit implements Writable { + private Range range; + private String[] locations; + private String tableId, tableName, instanceName, zooKeepers, principal; + private TokenSource tokenSource; + private String tokenFile; + private AuthenticationToken token; + private Boolean offline, mockInstance, isolatedScan, localIterators; + private Authorizations auths; + private Set<Pair<Text,Text>> fetchedColumns; + private List<IteratorSetting> iterators; + private Level level; + + public RangeInputSplit() { + range = new Range(); + locations = new String[0]; + tableName = ""; + tableId = ""; + } + + public RangeInputSplit(RangeInputSplit split) throws IOException { + this.setRange(split.getRange()); + this.setLocations(split.getLocations()); + this.setTableName(split.getTableName()); + this.setTableId(split.getTableId()); + } + + protected RangeInputSplit(String table, String tableId, Range range, String[] locations) { + this.range = range; + setLocations(locations); + this.tableName = table; + this.tableId = tableId; + } + + public Range getRange() { + return range; + } + + private static byte[] extractBytes(ByteSequence seq, int numBytes) { + byte[] bytes = new byte[numBytes + 1]; + bytes[0] = 0; + for (int i = 0; i < numBytes; i++) { + if (i >= seq.length()) + bytes[i + 1] = 0; + else + bytes[i + 1] = seq.byteAt(i); + } + return bytes; + } + + public static float getProgress(ByteSequence start, ByteSequence end, ByteSequence position) { + int maxDepth = Math.min(Math.max(end.length(), start.length()), position.length()); + BigInteger startBI = new BigInteger(extractBytes(start, maxDepth)); + BigInteger endBI = new BigInteger(extractBytes(end, maxDepth)); + BigInteger positionBI = new BigInteger(extractBytes(position, maxDepth)); + return (float) (positionBI.subtract(startBI).doubleValue() / endBI.subtract(startBI).doubleValue()); + } + + public float getProgress(Key currentKey) { + if (currentKey == null) + return 0f; + if (range.getStartKey() != null && range.getEndKey() != null) { + if (range.getStartKey().compareTo(range.getEndKey(), PartialKey.ROW) != 0) { + // just look at the row progress + return getProgress(range.getStartKey().getRowData(), range.getEndKey().getRowData(), currentKey.getRowData()); + } else if (range.getStartKey().compareTo(range.getEndKey(), PartialKey.ROW_COLFAM) != 0) { + // just look at the column family progress + return getProgress(range.getStartKey().getColumnFamilyData(), range.getEndKey().getColumnFamilyData(), currentKey.getColumnFamilyData()); + } else if (range.getStartKey().compareTo(range.getEndKey(), PartialKey.ROW_COLFAM_COLQUAL) != 0) { + // just look at the column qualifier progress + return getProgress(range.getStartKey().getColumnQualifierData(), range.getEndKey().getColumnQualifierData(), currentKey.getColumnQualifierData()); + } + } + // if we can't figure it out, then claim no progress + return 0f; + } + + /** + * This implementation of length is only an estimate, it does not provide exact values. Do not have your code rely on this return value. + */ + @Override + public long getLength() throws IOException { + Text startRow = range.isInfiniteStartKey() ? new Text(new byte[] {Byte.MIN_VALUE}) : range.getStartKey().getRow(); + Text stopRow = range.isInfiniteStopKey() ? new Text(new byte[] {Byte.MAX_VALUE}) : range.getEndKey().getRow(); + int maxCommon = Math.min(7, Math.min(startRow.getLength(), stopRow.getLength())); + long diff = 0; + + byte[] start = startRow.getBytes(); + byte[] stop = stopRow.getBytes(); + for (int i = 0; i < maxCommon; ++i) { + diff |= 0xff & (start[i] ^ stop[i]); + diff <<= Byte.SIZE; + } + + if (startRow.getLength() != stopRow.getLength()) + diff |= 0xff; + + return diff + 1; + } + + @Override + public String[] getLocations() throws IOException { + return Arrays.copyOf(locations, locations.length); + } + + @Override + public void readFields(DataInput in) throws IOException { + range.readFields(in); + tableName = in.readUTF(); + tableId = in.readUTF(); + int numLocs = in.readInt(); + locations = new String[numLocs]; + for (int i = 0; i < numLocs; ++i) + locations[i] = in.readUTF(); + + if (in.readBoolean()) { + isolatedScan = in.readBoolean(); + } + + if (in.readBoolean()) { + offline = in.readBoolean(); + } + + if (in.readBoolean()) { + localIterators = in.readBoolean(); + } + + if (in.readBoolean()) { + mockInstance = in.readBoolean(); + } + + if (in.readBoolean()) { + int numColumns = in.readInt(); + List<String> columns = new ArrayList<String>(numColumns); + for (int i = 0; i < numColumns; i++) { + columns.add(in.readUTF()); + } + + fetchedColumns = InputConfigurator.deserializeFetchedColumns(columns); + } + + if (in.readBoolean()) { + String strAuths = in.readUTF(); - auths = new Authorizations(strAuths.getBytes(StandardCharsets.UTF_8)); ++ auths = new Authorizations(strAuths.getBytes(UTF_8)); + } + + if (in.readBoolean()) { + principal = in.readUTF(); + } + + if (in.readBoolean()) { + int ordinal = in.readInt(); + this.tokenSource = TokenSource.values()[ordinal]; + + switch (this.tokenSource) { + case INLINE: + String tokenClass = in.readUTF(); - byte[] base64TokenBytes = in.readUTF().getBytes(StandardCharsets.UTF_8); ++ byte[] base64TokenBytes = in.readUTF().getBytes(UTF_8); + byte[] tokenBytes = Base64.decodeBase64(base64TokenBytes); + + this.token = AuthenticationTokenSerializer.deserialize(tokenClass, tokenBytes); + break; + + case FILE: + this.tokenFile = in.readUTF(); + + break; + default: + throw new IOException("Cannot parse unknown TokenSource ordinal"); + } + } + + if (in.readBoolean()) { + instanceName = in.readUTF(); + } + + if (in.readBoolean()) { + zooKeepers = in.readUTF(); + } + + if (in.readBoolean()) { + int numIterators = in.readInt(); + iterators = new ArrayList<IteratorSetting>(numIterators); + for (int i = 0; i < numIterators; i++) { + iterators.add(new IteratorSetting(in)); + } + } + + if (in.readBoolean()) { + level = Level.toLevel(in.readInt()); + } + } + + @Override + public void write(DataOutput out) throws IOException { + range.write(out); + out.writeUTF(tableName); + out.writeUTF(tableId); + out.writeInt(locations.length); + for (int i = 0; i < locations.length; ++i) + out.writeUTF(locations[i]); + + out.writeBoolean(null != isolatedScan); + if (null != isolatedScan) { + out.writeBoolean(isolatedScan); + } + + out.writeBoolean(null != offline); + if (null != offline) { + out.writeBoolean(offline); + } + + out.writeBoolean(null != localIterators); + if (null != localIterators) { + out.writeBoolean(localIterators); + } + + out.writeBoolean(null != mockInstance); + if (null != mockInstance) { + out.writeBoolean(mockInstance); + } + + out.writeBoolean(null != fetchedColumns); + if (null != fetchedColumns) { + String[] cols = InputConfigurator.serializeColumns(fetchedColumns); + out.writeInt(cols.length); + for (String col : cols) { + out.writeUTF(col); + } + } + + out.writeBoolean(null != auths); + if (null != auths) { + out.writeUTF(auths.serialize()); + } + + out.writeBoolean(null != principal); + if (null != principal) { + out.writeUTF(principal); + } + + out.writeBoolean(null != tokenSource); + if (null != tokenSource) { + out.writeInt(tokenSource.ordinal()); + + if (null != token && null != tokenFile) { + throw new IOException("Cannot use both inline AuthenticationToken and file-based AuthenticationToken"); + } else if (null != token) { + out.writeUTF(token.getClass().getCanonicalName()); + out.writeUTF(Base64.encodeBase64String(AuthenticationTokenSerializer.serialize(token))); + } else { + out.writeUTF(tokenFile); + } + } + + out.writeBoolean(null != instanceName); + if (null != instanceName) { + out.writeUTF(instanceName); + } + + out.writeBoolean(null != zooKeepers); + if (null != zooKeepers) { + out.writeUTF(zooKeepers); + } + + out.writeBoolean(null != iterators); + if (null != iterators) { + out.writeInt(iterators.size()); + for (IteratorSetting iterator : iterators) { + iterator.write(out); + } + } + + out.writeBoolean(null != level); + if (null != level) { + out.writeInt(level.toInt()); + } + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(256); + sb.append("Range: ").append(range); + sb.append(" Locations: ").append(Arrays.asList(locations)); + sb.append(" Table: ").append(tableName); + sb.append(" TableID: ").append(tableId); + sb.append(" InstanceName: ").append(instanceName); + sb.append(" zooKeepers: ").append(zooKeepers); + sb.append(" principal: ").append(principal); + sb.append(" tokenSource: ").append(tokenSource); + sb.append(" authenticationToken: ").append(token); + sb.append(" authenticationTokenFile: ").append(tokenFile); + sb.append(" Authorizations: ").append(auths); + sb.append(" offlineScan: ").append(offline); + sb.append(" mockInstance: ").append(mockInstance); + sb.append(" isolatedScan: ").append(isolatedScan); + sb.append(" localIterators: ").append(localIterators); + sb.append(" fetchColumns: ").append(fetchedColumns); + sb.append(" iterators: ").append(iterators); + sb.append(" logLevel: ").append(level); + return sb.toString(); + } + + /** + * Use {@link #getTableName} + */ + @Deprecated + public String getTable() { + return getTableName(); + } + + public String getTableName() { + return tableName; + } + + /** + * Use {@link #setTableName} + */ + @Deprecated + public void setTable(String table) { + setTableName(table); + } + + public void setTableName(String table) { + this.tableName = table; + } + + public void setTableId(String tableId) { + this.tableId = tableId; + } + + public String getTableId() { + return tableId; + } + + public Instance getInstance() { + if (null == instanceName) { + return null; + } + + if (isMockInstance()) { + return new MockInstance(getInstanceName()); + } + + if (null == zooKeepers) { + return null; + } + + return new ZooKeeperInstance(ClientConfiguration.loadDefault().withInstance(getInstanceName()).withZkHosts(getZooKeepers())); + } + + public String getInstanceName() { + return instanceName; + } + + public void setInstanceName(String instanceName) { + this.instanceName = instanceName; + } + + public String getZooKeepers() { + return zooKeepers; + } + + public void setZooKeepers(String zooKeepers) { + this.zooKeepers = zooKeepers; + } + + public String getPrincipal() { + return principal; + } + + public void setPrincipal(String principal) { + this.principal = principal; + } + + public AuthenticationToken getToken() { + return token; + } + + public void setToken(AuthenticationToken token) { + this.tokenSource = TokenSource.INLINE; + this.token = token; + } + + public void setToken(String tokenFile) { + this.tokenSource = TokenSource.FILE; + this.tokenFile = tokenFile; + } + + public Boolean isOffline() { + return offline; + } + + public void setOffline(Boolean offline) { + this.offline = offline; + } + + public void setLocations(String[] locations) { + this.locations = Arrays.copyOf(locations, locations.length); + } + + public Boolean isMockInstance() { + return mockInstance; + } + + public void setMockInstance(Boolean mockInstance) { + this.mockInstance = mockInstance; + } + + public Boolean isIsolatedScan() { + return isolatedScan; + } + + public void setIsolatedScan(Boolean isolatedScan) { + this.isolatedScan = isolatedScan; + } + + public Authorizations getAuths() { + return auths; + } + + public void setAuths(Authorizations auths) { + this.auths = auths; + } + + public void setRange(Range range) { + this.range = range; + } + + public Boolean usesLocalIterators() { + return localIterators; + } + + public void setUsesLocalIterators(Boolean localIterators) { + this.localIterators = localIterators; + } + + public Set<Pair<Text,Text>> getFetchedColumns() { + return fetchedColumns; + } + + public void setFetchedColumns(Collection<Pair<Text,Text>> fetchedColumns) { + this.fetchedColumns = new HashSet<Pair<Text,Text>>(); + for (Pair<Text,Text> columns : fetchedColumns) { + this.fetchedColumns.add(columns); + } + } + + public void setFetchedColumns(Set<Pair<Text,Text>> fetchedColumns) { + this.fetchedColumns = fetchedColumns; + } + + public List<IteratorSetting> getIterators() { + return iterators; + } + + public void setIterators(List<IteratorSetting> iterators) { + this.iterators = iterators; + } + + public Level getLogLevel() { + return level; + } + + public void setLogLevel(Level level) { + this.level = level; + } +} http://git-wip-us.apache.org/repos/asf/accumulo/blob/cfbdef13/mapreduce/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/impl/ConfiguratorBase.java ---------------------------------------------------------------------- diff --cc mapreduce/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/impl/ConfiguratorBase.java index 2d9fc04,0000000..ae1d46f mode 100644,000000..100644 --- a/mapreduce/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/impl/ConfiguratorBase.java +++ b/mapreduce/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/impl/ConfiguratorBase.java @@@ -1,405 -1,0 +1,404 @@@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.accumulo.core.client.mapreduce.lib.impl; + +import static com.google.common.base.Preconditions.checkArgument; ++import static java.nio.charset.StandardCharsets.UTF_8; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; - import java.nio.charset.StandardCharsets; - +import org.apache.accumulo.core.Constants; +import org.apache.accumulo.core.client.AccumuloSecurityException; +import org.apache.accumulo.core.client.ClientConfiguration; +import org.apache.accumulo.core.client.Instance; +import org.apache.accumulo.core.client.ZooKeeperInstance; +import org.apache.accumulo.core.client.mock.MockInstance; +import org.apache.accumulo.core.client.security.tokens.AuthenticationToken; +import org.apache.accumulo.core.client.security.tokens.AuthenticationToken.AuthenticationTokenSerializer; +import org.apache.accumulo.core.security.Credentials; +import org.apache.accumulo.core.util.Base64; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FSDataInputStream; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.util.StringUtils; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; + +/** + * @since 1.6.0 + */ +public class ConfiguratorBase { + + /** + * Configuration keys for {@link Instance#getConnector(String, AuthenticationToken)}. + * + * @since 1.6.0 + */ + public static enum ConnectorInfo { + IS_CONFIGURED, PRINCIPAL, TOKEN, + } + + public static enum TokenSource { + FILE, INLINE; + + private String prefix; + + private TokenSource() { + prefix = name().toLowerCase() + ":"; + } + + public String prefix() { + return prefix; + } + } + + /** + * Configuration keys for {@link Instance}, {@link ZooKeeperInstance}, and {@link MockInstance}. + * + * @since 1.6.0 + */ + public static enum InstanceOpts { + TYPE, NAME, ZOO_KEEPERS, CLIENT_CONFIG; + } + + /** + * Configuration keys for general configuration options. + * + * @since 1.6.0 + */ + public static enum GeneralOpts { + LOG_LEVEL, + VISIBILITY_CACHE_SIZE + } + + /** + * Provides a configuration key for a given feature enum, prefixed by the implementingClass + * + * @param implementingClass + * the class whose name will be used as a prefix for the property configuration key + * @param e + * the enum used to provide the unique part of the configuration key + * @return the configuration key + * @since 1.6.0 + */ + protected static String enumToConfKey(Class<?> implementingClass, Enum<?> e) { + return implementingClass.getSimpleName() + "." + e.getDeclaringClass().getSimpleName() + "." + StringUtils.camelize(e.name().toLowerCase()); + } + + /** + * Provides a configuration key for a given feature enum. + * + * @param e + * the enum used to provide the unique part of the configuration key + * @return the configuration key + */ + protected static String enumToConfKey(Enum<?> e) { + return e.getDeclaringClass().getSimpleName() + "." + StringUtils.camelize(e.name().toLowerCase()); + } + + /** + * Sets the connector information needed to communicate with Accumulo in this job. + * + * <p> + * <b>WARNING:</b> The serialized token 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. + * + * @param implementingClass + * the class whose name will be used as a prefix for the property configuration key + * @param conf + * the Hadoop configuration object to configure + * @param principal + * a valid Accumulo user name + * @param token + * the user's password + * @since 1.6.0 + */ + public static void setConnectorInfo(Class<?> implementingClass, Configuration conf, String principal, AuthenticationToken token) + throws AccumuloSecurityException { + if (isConnectorInfoSet(implementingClass, conf)) + throw new IllegalStateException("Connector info for " + implementingClass.getSimpleName() + " can only be set once per job"); + + checkArgument(principal != null, "principal is null"); + checkArgument(token != null, "token is null"); + conf.setBoolean(enumToConfKey(implementingClass, ConnectorInfo.IS_CONFIGURED), true); + conf.set(enumToConfKey(implementingClass, ConnectorInfo.PRINCIPAL), principal); + conf.set(enumToConfKey(implementingClass, ConnectorInfo.TOKEN), + TokenSource.INLINE.prefix() + token.getClass().getName() + ":" + Base64.encodeBase64String(AuthenticationTokenSerializer.serialize(token))); + } + + /** + * Sets the connector information needed to communicate with Accumulo in this job. + * + * <p> + * Pulls a token file into the Distributed Cache that contains the authentication token in an attempt to be more secure than storing the password in the + * Configuration. Token file created with "bin/accumulo create-token". + * + * @param implementingClass + * the class whose name will be used as a prefix for the property configuration key + * @param conf + * the Hadoop configuration object to configure + * @param principal + * a valid Accumulo user name + * @param tokenFile + * the path to the token file in DFS + * @since 1.6.0 + */ + public static void setConnectorInfo(Class<?> implementingClass, Configuration conf, String principal, String tokenFile) throws AccumuloSecurityException { + if (isConnectorInfoSet(implementingClass, conf)) + throw new IllegalStateException("Connector info for " + implementingClass.getSimpleName() + " can only be set once per job"); + + checkArgument(principal != null, "principal is null"); + checkArgument(tokenFile != null, "tokenFile is null"); + + try { + DistributedCacheHelper.addCacheFile(new URI(tokenFile), conf); + } catch (URISyntaxException e) { + throw new IllegalStateException("Unable to add tokenFile \"" + tokenFile + "\" to distributed cache."); + } + + conf.setBoolean(enumToConfKey(implementingClass, ConnectorInfo.IS_CONFIGURED), true); + conf.set(enumToConfKey(implementingClass, ConnectorInfo.PRINCIPAL), principal); + conf.set(enumToConfKey(implementingClass, ConnectorInfo.TOKEN), TokenSource.FILE.prefix() + tokenFile); + } + + /** + * Determines if the connector info has already been set for this instance. + * + * @param implementingClass + * the class whose name will be used as a prefix for the property configuration key + * @param conf + * the Hadoop configuration object to configure + * @return true if the connector info has already been set, false otherwise + * @since 1.6.0 + * @see #setConnectorInfo(Class, Configuration, String, AuthenticationToken) + */ + public static Boolean isConnectorInfoSet(Class<?> implementingClass, Configuration conf) { + return conf.getBoolean(enumToConfKey(implementingClass, ConnectorInfo.IS_CONFIGURED), false); + } + + /** + * Gets the user name from the configuration. + * + * @param implementingClass + * the class whose name will be used as a prefix for the property configuration key + * @param conf + * the Hadoop configuration object to configure + * @return the principal + * @since 1.6.0 + * @see #setConnectorInfo(Class, Configuration, String, AuthenticationToken) + */ + public static String getPrincipal(Class<?> implementingClass, Configuration conf) { + return conf.get(enumToConfKey(implementingClass, ConnectorInfo.PRINCIPAL)); + } + + /** + * Gets the authenticated token from either the specified token file or directly from the configuration, whichever was used when the job was configured. + * + * @param implementingClass + * the class whose name will be used as a prefix for the property configuration key + * @param conf + * the Hadoop configuration object to configure + * @return the principal's authentication token + * @since 1.6.0 + * @see #setConnectorInfo(Class, Configuration, String, AuthenticationToken) + * @see #setConnectorInfo(Class, Configuration, String, String) + */ + public static AuthenticationToken getAuthenticationToken(Class<?> implementingClass, Configuration conf) { + String token = conf.get(enumToConfKey(implementingClass, ConnectorInfo.TOKEN)); + if (token == null || token.isEmpty()) + return null; + if (token.startsWith(TokenSource.INLINE.prefix())) { + String[] args = token.substring(TokenSource.INLINE.prefix().length()).split(":", 2); + if (args.length == 2) - return AuthenticationTokenSerializer.deserialize(args[0], Base64.decodeBase64(args[1].getBytes(StandardCharsets.UTF_8))); ++ return AuthenticationTokenSerializer.deserialize(args[0], Base64.decodeBase64(args[1].getBytes(UTF_8))); + } else if (token.startsWith(TokenSource.FILE.prefix())) { + String tokenFileName = token.substring(TokenSource.FILE.prefix().length()); + return getTokenFromFile(conf, getPrincipal(implementingClass, conf), tokenFileName); + } + + throw new IllegalStateException("Token was not properly serialized into the configuration"); + } + + /** + * Reads from the token file in distributed cache. Currently, the token file stores data separated by colons e.g. principal:token_class:token + * + * @param conf + * the Hadoop context for the configured job + * @return path to the token file as a String + * @since 1.6.0 + * @see #setConnectorInfo(Class, Configuration, String, AuthenticationToken) + */ + public static AuthenticationToken getTokenFromFile(Configuration conf, String principal, String tokenFile) { + FSDataInputStream in = null; + try { + URI[] uris = DistributedCacheHelper.getCacheFiles(conf); + Path path = null; + for (URI u : uris) { + if (u.toString().equals(tokenFile)) { + path = new Path(u); + } + } + if (path == null) { + throw new IllegalArgumentException("Couldn't find password file called \"" + tokenFile + "\" in cache."); + } + FileSystem fs = FileSystem.get(conf); + in = fs.open(path); + } catch (IOException e) { + throw new IllegalArgumentException("Couldn't open password file called \"" + tokenFile + "\"."); + } + try (java.util.Scanner fileScanner = new java.util.Scanner(in)) { + while (fileScanner.hasNextLine()) { + Credentials creds = Credentials.deserialize(fileScanner.nextLine()); + if (principal.equals(creds.getPrincipal())) { + return creds.getToken(); + } + } + throw new IllegalArgumentException("Couldn't find token for user \"" + principal + "\" in file \"" + tokenFile + "\""); + } + } + + /** + * Configures a {@link ZooKeeperInstance} for this job. + * + * @param implementingClass + * the class whose name will be used as a prefix for the property configuration key + * @param conf + * the Hadoop configuration object to configure + * @param clientConfig + * client configuration for specifying connection timeouts, SSL connection options, etc. + * @since 1.6.0 + */ + public static void setZooKeeperInstance(Class<?> implementingClass, Configuration conf, ClientConfiguration clientConfig) { + String key = enumToConfKey(implementingClass, InstanceOpts.TYPE); + 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"); + if (clientConfig != null) { + conf.set(enumToConfKey(implementingClass, InstanceOpts.CLIENT_CONFIG), clientConfig.serialize()); + } + } + + /** + * Configures a {@link MockInstance} for this job. + * + * @param implementingClass + * the class whose name will be used as a prefix for the property configuration key + * @param conf + * the Hadoop configuration object to configure + * @param instanceName + * the Accumulo instance name + * @since 1.6.0 + */ + public static void setMockInstance(Class<?> implementingClass, Configuration conf, String instanceName) { + String key = enumToConfKey(implementingClass, InstanceOpts.TYPE); + 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"); + + checkArgument(instanceName != null, "instanceName is null"); + conf.set(enumToConfKey(implementingClass, InstanceOpts.NAME), instanceName); + } + + /** + * Initializes an Accumulo {@link Instance} based on the configuration. + * + * @param implementingClass + * the class whose name will be used as a prefix for the property configuration key + * @param conf + * the Hadoop configuration object to configure + * @return an Accumulo instance + * @since 1.6.0 + * @see #setZooKeeperInstance(Class, Configuration, ClientConfiguration) + * @see #setMockInstance(Class, Configuration, String) + */ + public static Instance getInstance(Class<?> implementingClass, Configuration conf) { + String instanceType = conf.get(enumToConfKey(implementingClass, InstanceOpts.TYPE), ""); + if ("MockInstance".equals(instanceType)) + return new MockInstance(conf.get(enumToConfKey(implementingClass, InstanceOpts.NAME))); + else if ("ZooKeeperInstance".equals(instanceType)) { + String clientConfigString = conf.get(enumToConfKey(implementingClass, InstanceOpts.CLIENT_CONFIG)); + if (clientConfigString == null) { + String instanceName = conf.get(enumToConfKey(implementingClass, InstanceOpts.NAME)); + String zookeepers = conf.get(enumToConfKey(implementingClass, InstanceOpts.ZOO_KEEPERS)); + return new ZooKeeperInstance(ClientConfiguration.loadDefault().withInstance(instanceName).withZkHosts(zookeepers)); + } else { + return new ZooKeeperInstance(ClientConfiguration.deserialize(clientConfigString)); + } + } else if (instanceType.isEmpty()) + throw new IllegalStateException("Instance has not been configured for " + implementingClass.getSimpleName()); + else + throw new IllegalStateException("Unrecognized instance type " + instanceType); + } + + /** + * Sets the log level for this job. + * + * @param implementingClass + * the class whose name will be used as a prefix for the property configuration key + * @param conf + * the Hadoop configuration object to configure + * @param level + * the logging level + * @since 1.6.0 + */ + public static void setLogLevel(Class<?> implementingClass, Configuration conf, Level level) { + checkArgument(level != null, "level is null"); + Logger.getLogger(implementingClass).setLevel(level); + conf.setInt(enumToConfKey(implementingClass, GeneralOpts.LOG_LEVEL), level.toInt()); + } + + /** + * Gets the log level from this configuration. + * + * @param implementingClass + * the class whose name will be used as a prefix for the property configuration key + * @param conf + * the Hadoop configuration object to configure + * @return the log level + * @since 1.6.0 + * @see #setLogLevel(Class, Configuration, Level) + */ + public static Level getLogLevel(Class<?> implementingClass, Configuration conf) { + return Level.toLevel(conf.getInt(enumToConfKey(implementingClass, GeneralOpts.LOG_LEVEL), Level.INFO.toInt())); + } + + /** + * Sets the valid visibility count for this job. + * + * @param conf + * the Hadoop configuration object to configure + * @param visibilityCacheSize + * the LRU cache size + */ + public static void setVisibilityCacheSize(Configuration conf, int visibilityCacheSize) { + conf.setInt(enumToConfKey(GeneralOpts.VISIBILITY_CACHE_SIZE), visibilityCacheSize); + } + + /** + * Gets the valid visibility count for this job. + * + * @param conf + * the Hadoop configuration object to configure + * @return the valid visibility count + */ + public static int getVisibilityCacheSize(Configuration conf) { + return conf.getInt(enumToConfKey(GeneralOpts.VISIBILITY_CACHE_SIZE),Constants.DEFAULT_VISIBILITY_CACHE_SIZE); + } + +}