Skip to content

Commit 469be3d

Browse files
committed
HBASE-28432 Refactor tools which are under test packaging to a new module hbase-tools
1 parent 4446d29 commit 469be3d

File tree

74 files changed

+1019
-177
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1019
-177
lines changed

hbase-assembly/src/main/assembly/hadoop-three-compat.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<include>org.apache.hbase:hbase-it</include>
4747
<include>org.apache.hbase:hbase-logging</include>
4848
<include>org.apache.hbase:hbase-mapreduce</include>
49+
<include>org.apache.hbase:hbase-diagnostics</include>
4950
<include>org.apache.hbase:hbase-metrics</include>
5051
<include>org.apache.hbase:hbase-metrics-api</include>
5152
<include>org.apache.hbase:hbase-procedure</include>

hbase-asyncfs/src/test/java/org/apache/hadoop/hbase/security/HBaseKerberosUtils.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
package org.apache.hadoop.hbase.security;
1919

2020
import java.io.File;
21-
import java.io.IOException;
22-
import java.net.InetAddress;
2321
import org.apache.hadoop.conf.Configuration;
2422
import org.apache.hadoop.fs.CommonConfigurationKeys;
2523
import org.apache.hadoop.hbase.AuthUtil;
@@ -172,23 +170,6 @@ public static void setSSLConfiguration(HBaseCommonTestingUtil utility, Class<?>
172170
KeyStoreTestUtil.setupSSLConfig(keystoresDir.getAbsolutePath(), sslConfDir, conf, false);
173171
}
174172

175-
public static UserGroupInformation loginAndReturnUGI(Configuration conf, String username)
176-
throws IOException {
177-
String hostname = InetAddress.getLocalHost().getHostName();
178-
String keyTabFileConfKey = "hbase." + username + ".keytab.file";
179-
String keyTabFileLocation = conf.get(keyTabFileConfKey);
180-
String principalConfKey = "hbase." + username + ".kerberos.principal";
181-
String principal = org.apache.hadoop.security.SecurityUtil
182-
.getServerPrincipal(conf.get(principalConfKey), hostname);
183-
if (keyTabFileLocation == null || principal == null) {
184-
LOG.warn(
185-
"Principal or key tab file null for : " + principalConfKey + ", " + keyTabFileConfKey);
186-
}
187-
UserGroupInformation ugi =
188-
UserGroupInformation.loginUserFromKeytabAndReturnUGI(principal, keyTabFileLocation);
189-
return ugi;
190-
}
191-
192173
public static UserGroupInformation loginKerberosPrincipal(String krbKeytab, String krbPrincipal)
193174
throws Exception {
194175
Configuration conf = new Configuration();

hbase-common/src/test/java/org/apache/hadoop/hbase/io/compress/CompressionTestBase.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.apache.hadoop.conf.Configurable;
2727
import org.apache.hadoop.hbase.util.Bytes;
2828
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
29-
import org.apache.hadoop.hbase.util.RandomDistribution;
29+
import org.apache.hadoop.hbase.util.RandomDistributionCopy;
3030
import org.apache.hadoop.io.IOUtils;
3131
import org.apache.hadoop.io.compress.CompressionCodec;
3232
import org.apache.hadoop.io.compress.CompressionInputStream;
@@ -128,8 +128,8 @@ protected void codecSmallTest(final CompressionCodec codec) throws Exception {
128128
* Test with a large input (1MB) divided into blocks of 4KB.
129129
*/
130130
protected void codecLargeTest(final CompressionCodec codec, final double sigma) throws Exception {
131-
RandomDistribution.DiscreteRNG rng =
132-
new RandomDistribution.Zipf(new Random(), 0, Byte.MAX_VALUE, sigma);
131+
RandomDistributionCopy.DiscreteRNG rng =
132+
new RandomDistributionCopy.Zipf(new Random(), 0, Byte.MAX_VALUE, sigma);
133133
final byte[][] input = new byte[LARGE_SIZE / BLOCK_SIZE][BLOCK_SIZE];
134134
fill(rng, input);
135135
codecTest(codec, input);
@@ -140,20 +140,20 @@ protected void codecLargeTest(final CompressionCodec codec, final double sigma)
140140
*/
141141
protected void codecVeryLargeTest(final CompressionCodec codec, final double sigma)
142142
throws Exception {
143-
RandomDistribution.DiscreteRNG rng =
144-
new RandomDistribution.Zipf(new Random(), 0, Byte.MAX_VALUE, sigma);
143+
RandomDistributionCopy.DiscreteRNG rng =
144+
new RandomDistributionCopy.Zipf(new Random(), 0, Byte.MAX_VALUE, sigma);
145145
final byte[][] input = new byte[1][VERY_LARGE_SIZE];
146146
fill(rng, input);
147147
codecTest(codec, input);
148148
}
149149

150-
protected static void fill(RandomDistribution.DiscreteRNG rng, byte[][] input) {
150+
protected static void fill(RandomDistributionCopy.DiscreteRNG rng, byte[][] input) {
151151
for (int i = 0; i < input.length; i++) {
152152
fill(rng, input[i]);
153153
}
154154
}
155155

156-
protected static void fill(RandomDistribution.DiscreteRNG rng, byte[] input) {
156+
protected static void fill(RandomDistributionCopy.DiscreteRNG rng, byte[] input) {
157157
for (int i = 0; i < input.length; i++) {
158158
input[i] = (byte) rng.nextInt();
159159
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hbase.io.crypto;
19+
20+
import java.security.Key;
21+
import javax.crypto.spec.SecretKeySpec;
22+
23+
/**
24+
* Return a fixed secret key for AES for testing.
25+
*/
26+
public class KeyProviderForTestingCopy implements KeyProvider {
27+
28+
@Override
29+
public void init(String parameters) {
30+
}
31+
32+
@Override
33+
public Key getKey(String name) {
34+
return new SecretKeySpec(Encryption.hash128(name), "AES");
35+
}
36+
37+
@Override
38+
public Key[] getKeys(String[] aliases) {
39+
Key[] result = new Key[aliases.length];
40+
for (int i = 0; i < aliases.length; i++) {
41+
result[i] = new SecretKeySpec(Encryption.hash128(aliases[i]), "AES");
42+
}
43+
return result;
44+
}
45+
}
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hbase.util;
19+
20+
import java.util.ArrayList;
21+
import java.util.Arrays;
22+
import java.util.Collections;
23+
import java.util.Random;
24+
25+
/**
26+
* A class that generates random numbers that follow some distribution.
27+
* <p>
28+
* Copied from <a href="https://issues.apache.org/jira/browse/HADOOP-3315">hadoop-3315 tfile</a>.
29+
* Remove after tfile is committed and use the tfile version of this class instead.
30+
* </p>
31+
*/
32+
public class RandomDistributionCopy {
33+
/**
34+
* Interface for discrete (integer) random distributions.
35+
*/
36+
public interface DiscreteRNG {
37+
/**
38+
* Get the next random number
39+
* @return the next random number.
40+
*/
41+
int nextInt();
42+
}
43+
44+
/**
45+
* P(i)=1/(max-min)
46+
*/
47+
public static final class Flat implements DiscreteRNG {
48+
private final Random random;
49+
private final int min;
50+
private final int max;
51+
52+
/**
53+
* Generate random integers from min (inclusive) to max (exclusive) following even distribution.
54+
* The basic random number generator. Minimum integer maximum integer (exclusive).
55+
*/
56+
public Flat(Random random, int min, int max) {
57+
if (min >= max) {
58+
throw new IllegalArgumentException("Invalid range");
59+
}
60+
this.random = random;
61+
this.min = min;
62+
this.max = max;
63+
}
64+
65+
/**
66+
* @see DiscreteRNG#nextInt()
67+
*/
68+
@Override
69+
public int nextInt() {
70+
return random.nextInt(max - min) + min;
71+
}
72+
}
73+
74+
/**
75+
* Zipf distribution. The ratio of the probabilities of integer i and j is defined as follows:
76+
* P(i)/P(j)=((j-min+1)/(i-min+1))^sigma.
77+
*/
78+
public static final class Zipf implements DiscreteRNG {
79+
private static final double DEFAULT_EPSILON = 0.001;
80+
private final Random random;
81+
private final ArrayList<Integer> k;
82+
private final ArrayList<Double> v;
83+
84+
/**
85+
* Constructor The random number generator. minimum integer (inclusvie) maximum integer
86+
* (exclusive) parameter sigma. (sigma > 1.0)
87+
*/
88+
public Zipf(Random r, int min, int max, double sigma) {
89+
this(r, min, max, sigma, DEFAULT_EPSILON);
90+
}
91+
92+
/**
93+
* Constructor. The random number generator. minimum integer (inclusvie) maximum integer
94+
* (exclusive) parameter sigma. (sigma > 1.0) Allowable error percentage (0 < epsilon < 1.0).
95+
*/
96+
public Zipf(Random r, int min, int max, double sigma, double epsilon) {
97+
if ((max <= min) || (sigma <= 1) || (epsilon <= 0) || (epsilon >= 0.5)) {
98+
throw new IllegalArgumentException("Invalid arguments");
99+
}
100+
random = r;
101+
k = new ArrayList<>();
102+
v = new ArrayList<>();
103+
104+
double sum = 0;
105+
int last = -1;
106+
for (int i = min; i < max; ++i) {
107+
sum += Math.exp(-sigma * Math.log(i - min + 1));
108+
if ((last == -1) || i * (1 - epsilon) > last) {
109+
k.add(i);
110+
v.add(sum);
111+
last = i;
112+
}
113+
}
114+
115+
if (last != max - 1) {
116+
k.add(max - 1);
117+
v.add(sum);
118+
}
119+
120+
v.set(v.size() - 1, 1.0);
121+
122+
for (int i = v.size() - 2; i >= 0; --i) {
123+
v.set(i, v.get(i) / sum);
124+
}
125+
}
126+
127+
/**
128+
* @see DiscreteRNG#nextInt()
129+
*/
130+
@Override
131+
public int nextInt() {
132+
double d = random.nextDouble();
133+
int idx = Collections.binarySearch(v, d);
134+
135+
if (idx > 0) {
136+
++idx;
137+
} else {
138+
idx = -(idx + 1);
139+
}
140+
141+
if (idx >= v.size()) {
142+
idx = v.size() - 1;
143+
}
144+
145+
if (idx == 0) {
146+
return k.get(0);
147+
}
148+
149+
int ceiling = k.get(idx);
150+
int lower = k.get(idx - 1);
151+
152+
return ceiling - random.nextInt(ceiling - lower);
153+
}
154+
}
155+
156+
/**
157+
* Binomial distribution. P(k)=select(n, k)*p^k*(1-p)^(n-k) (k = 0, 1, ..., n)
158+
* P(k)=select(max-min-1, k-min)*p^(k-min)*(1-p)^(k-min)*(1-p)^(max-k-1)
159+
*/
160+
public static final class Binomial implements DiscreteRNG {
161+
private final Random random;
162+
private final int min;
163+
private final int n;
164+
private final double[] v;
165+
166+
private static double select(int n, int k) {
167+
double ret = 1.0;
168+
for (int i = k + 1; i <= n; ++i) {
169+
ret *= (double) i / (i - k);
170+
}
171+
return ret;
172+
}
173+
174+
private static double power(double p, int k) {
175+
return Math.exp(k * Math.log(p));
176+
}
177+
178+
/**
179+
* Generate random integers from min (inclusive) to max (exclusive) following Binomial
180+
* distribution. The basic random number generator. Minimum integer maximum integer (exclusive).
181+
* parameter.
182+
*/
183+
public Binomial(Random random, int min, int max, double p) {
184+
if (min >= max) {
185+
throw new IllegalArgumentException("Invalid range");
186+
}
187+
this.random = random;
188+
this.min = min;
189+
this.n = max - min - 1;
190+
if (n > 0) {
191+
v = new double[n + 1];
192+
double sum = 0.0;
193+
for (int i = 0; i <= n; ++i) {
194+
sum += select(n, i) * power(p, i) * power(1 - p, n - i);
195+
v[i] = sum;
196+
}
197+
for (int i = 0; i <= n; ++i) {
198+
v[i] /= sum;
199+
}
200+
} else {
201+
v = null;
202+
}
203+
}
204+
205+
/**
206+
* @see DiscreteRNG#nextInt()
207+
*/
208+
@Override
209+
public int nextInt() {
210+
if (v == null) {
211+
return min;
212+
}
213+
double d = random.nextDouble();
214+
int idx = Arrays.binarySearch(v, d);
215+
if (idx > 0) {
216+
++idx;
217+
} else {
218+
idx = -(idx + 1);
219+
}
220+
221+
if (idx >= v.length) {
222+
idx = v.length - 1;
223+
}
224+
return idx + min;
225+
}
226+
}
227+
}

hbase-compression/hbase-compression-zstd/src/test/java/org/apache/hadoop/hbase/io/compress/zstd/TestZstdDictionary.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import org.apache.hadoop.hbase.io.compress.CompressionTestBase;
3131
import org.apache.hadoop.hbase.io.compress.DictionaryCache;
3232
import org.apache.hadoop.hbase.testclassification.SmallTests;
33-
import org.apache.hadoop.hbase.util.RandomDistribution;
33+
import org.apache.hadoop.hbase.util.RandomDistributionCopy;
3434
import org.junit.BeforeClass;
3535
import org.junit.ClassRule;
3636
import org.junit.Test;
@@ -82,8 +82,8 @@ public static void main(String[] args) throws IOException {
8282
System.err.println("Usage: TestZstdCodec <outFile>");
8383
System.exit(-1);
8484
}
85-
final RandomDistribution.DiscreteRNG rng =
86-
new RandomDistribution.Zipf(new Random(), 0, Byte.MAX_VALUE, 2);
85+
final RandomDistributionCopy.DiscreteRNG rng =
86+
new RandomDistributionCopy.Zipf(new Random(), 0, Byte.MAX_VALUE, 2);
8787
final File outFile = new File(args[0]);
8888
final byte[] buffer = new byte[1024];
8989
System.out.println("Generating " + outFile);

0 commit comments

Comments
 (0)