Skip to content

Commit 623c78b

Browse files
author
leongu-tc
committed
apache#1.2.1-SDP SDP
1 parent 8d8a710 commit 623c78b

File tree

47 files changed

+3181
-156
lines changed

Some content is hidden

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

47 files changed

+3181
-156
lines changed

bin/hbase-daemon.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,10 @@ case $startStop in
267267
;;
268268

269269
(stop)
270-
rm -f "$HBASE_START_FILE"
270+
if [ -f "${HBASE_START_FILE}" ];then
271+
rm -f "$HBASE_START_FILE"
272+
fi
273+
271274
if [ -f $HBASE_PID ]; then
272275
pidToKill=`cat $HBASE_PID`
273276
# kill -0 == see if the PID exists
@@ -283,7 +286,9 @@ case $startStop in
283286
else
284287
echo no $command to stop because no pid file $HBASE_PID
285288
fi
286-
rm -f $HBASE_PID
289+
if [ -f "${HBASE_PID}" ];then
290+
rm -f $HBASE_PID
291+
fi
287292
;;
288293

289294
(restart)

compile.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mvn clean install -DskipTests -Prelease -Drat.numUnapprovedLicenses=100
2+
mvn install -DskipTests site assembly:single -Prelease -Drat.numUnapprovedLicenses=100

hbase-annotations/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<artifactId>hbase</artifactId>
2525
<groupId>org.apache.hbase</groupId>
26-
<version>1.2.1</version>
26+
<version>1.2.1-SDP</version>
2727
<relativePath>..</relativePath>
2828
</parent>
2929

hbase-assembly/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<artifactId>hbase</artifactId>
2525
<groupId>org.apache.hbase</groupId>
26-
<version>1.2.1</version>
26+
<version>1.2.1-SDP</version>
2727
<relativePath>..</relativePath>
2828
</parent>
2929
<artifactId>hbase-assembly</artifactId>
@@ -38,7 +38,7 @@
3838
<build>
3939
<plugins>
4040
<!-- licensing info from our dependencies -->
41-
<plugin>
41+
<!--plugin>
4242
<groupId>org.apache.maven.plugins</groupId>
4343
<artifactId>maven-remote-resources-plugin</artifactId>
4444
<version>1.5</version>
@@ -66,7 +66,7 @@
6666
</configuration>
6767
</execution>
6868
</executions>
69-
</plugin>
69+
</plugin-->
7070
<plugin>
7171
<artifactId>maven-assembly-plugin</artifactId>
7272
<version>${maven.assembly.version}</version>

hbase-checkstyle/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
<modelVersion>4.0.0</modelVersion>
2525
<groupId>org.apache.hbase</groupId>
2626
<artifactId>hbase-checkstyle</artifactId>
27-
<version>1.2.1</version>
27+
<version>1.2.1-SDP</version>
2828
<name>Apache HBase - Checkstyle</name>
2929
<description>Module to hold Checkstyle properties for HBase.</description>
3030

3131
<parent>
3232
<artifactId>hbase</artifactId>
3333
<groupId>org.apache.hbase</groupId>
34-
<version>1.2.1</version>
34+
<version>1.2.1-SDP</version>
3535
<relativePath>..</relativePath>
3636
</parent>
3737

hbase-client/pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<parent>
2525
<artifactId>hbase</artifactId>
2626
<groupId>org.apache.hbase</groupId>
27-
<version>1.2.1</version>
27+
<version>1.2.1-SDP</version>
2828
<relativePath>..</relativePath>
2929
</parent>
3030

@@ -122,6 +122,11 @@
122122
<type>test-jar</type>
123123
<scope>test</scope>
124124
</dependency>
125+
<dependency>
126+
<groupId>com.cgws.sdp.auth</groupId>
127+
<artifactId>sdp-auth-common</artifactId>
128+
<version>0.0.1-SNAPSHOT</version>
129+
</dependency>
125130
<dependency>
126131
<groupId>org.apache.hbase</groupId>
127132
<artifactId>hbase-common</artifactId>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.apache.hadoop.hbase;
2+
3+
public class AuthFailedException extends MasterNotRunningException
4+
{
5+
public AuthFailedException(String s) {
6+
super(s);
7+
}
8+
}

hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionConfiguration.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
*/
2828
@InterfaceAudience.Private
2929
public class ConnectionConfiguration {
30-
30+
public static final String HBASE_AUTHENTICATION_SDP_PUBLICKEY = "hbase.security.authentication.sdp.publickey";
31+
public static final String HBASE_AUTHENTICATION_SDP_PRIVATEKEY = "hbase.security.authentication.sdp.privatekey";
32+
public static final String HBASE_AUTHENTICATION_SDP_PUBLICKEY_UNDERLINE = "hbase_security_authentication_sdp_publickey";
33+
public static final String HBASE_AUTHENTICATION_SDP_PRIVATEKEY_UNDERLINE = "hbase_security_authentication_sdp_privatekey";
3134
public static final String WRITE_BUFFER_SIZE_KEY = "hbase.client.write.buffer";
3235
public static final long WRITE_BUFFER_SIZE_DEFAULT = 2097152;
3336
public static final String MAX_KEYVALUE_SIZE_KEY = "hbase.client.keyvalue.maxsize";

hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionFactory.java

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,21 @@
2020

2121
import java.io.IOException;
2222
import java.lang.reflect.Constructor;
23+
import java.util.HashMap;
24+
import java.util.Map;
25+
import java.util.Properties;
2326
import java.util.concurrent.ExecutorService;
2427

28+
import org.apache.commons.lang.StringUtils;
2529
import org.apache.hadoop.hbase.classification.InterfaceAudience;
2630
import org.apache.hadoop.hbase.classification.InterfaceStability;
2731
import org.apache.hadoop.conf.Configuration;
2832
import org.apache.hadoop.hbase.HBaseConfiguration;
2933
import org.apache.hadoop.hbase.security.User;
3034
import org.apache.hadoop.hbase.security.UserProvider;
35+
import org.apache.hadoop.security.UserGroupInformation;
36+
import org.slf4j.Logger;
37+
import org.slf4j.LoggerFactory;
3138

3239

3340
/**
@@ -57,6 +64,13 @@
5764
@InterfaceAudience.Public
5865
@InterfaceStability.Evolving
5966
public class ConnectionFactory {
67+
private static final Logger LOG = LoggerFactory.getLogger(ConnectionFactory.class);
68+
public static Map<String, String> sdpAuthKeys = new HashMap<String, String>();
69+
70+
static{
71+
sdpAuthKeys.put("hbase_security_authentication_sdp_publickey", ConnectionConfiguration.HBASE_AUTHENTICATION_SDP_PUBLICKEY);
72+
sdpAuthKeys.put("hbase_security_authentication_sdp_privatekey", ConnectionConfiguration.HBASE_AUTHENTICATION_SDP_PRIVATEKEY);
73+
}
6074

6175
/** No public c.tors */
6276
protected ConnectionFactory() {
@@ -210,17 +224,58 @@ public static Connection createConnection(Configuration conf, User user)
210224
*/
211225
public static Connection createConnection(Configuration conf, ExecutorService pool, User user)
212226
throws IOException {
227+
// if (user == null) {
228+
// UserProvider provider = UserProvider.instantiate(conf);
229+
// user = provider.getCurrent();
230+
// }
231+
213232
if (user == null) {
214233
UserProvider provider = UserProvider.instantiate(conf);
215-
user = provider.getCurrent();
234+
try {
235+
user = provider.getCurrent();
236+
} catch (Exception e) {
237+
LOG.warn("Failed to get current user from configuration.", e);
238+
user = null;
239+
}
240+
241+
if (user == null) {
242+
user = getCurrentUser();
243+
}
216244
}
217245

218246
return createConnection(conf, false, pool, user);
219247
}
248+
249+
private static User getCurrentUser(){
250+
String currentUserName = System.getProperty("user.name");
251+
if(StringUtils.isBlank(currentUserName)){
252+
LOG.warn("The current user name is blank, and set it to hbase user.");
253+
currentUserName = "hbase";
254+
}
255+
256+
return new User.SecureHadoopUser(UserGroupInformation.createRemoteUser(currentUserName));
257+
}
258+
259+
public static void loadSdpAuthParams(Configuration conf){
260+
LOG.debug("start load auth param from env or sys properties...");
261+
Map<String, String> envs = System.getenv();
262+
Properties sysProps = System.getProperties();
263+
for( String key : sdpAuthKeys.keySet() ){
264+
if( envs.get(key) != null ){
265+
conf.set(sdpAuthKeys.get(key),envs.get(key));
266+
LOG.debug("loaded hbase authentication parameter from evn. key:{} value:{}",key,envs.get(key));
267+
}else if( sysProps.get(key) != null ){
268+
conf.set(sdpAuthKeys.get(key),(String)sysProps.get(key));
269+
LOG.debug("loaded hbase authentication parameter from conf. key:{} value:{}",key,(String)sysProps.get(key));
270+
}
271+
}
272+
}
220273

221274
static Connection createConnection(final Configuration conf, final boolean managed,
222275
final ExecutorService pool, final User user)
223276
throws IOException {
277+
loadSdpAuthParams(conf);
278+
224279
String className = conf.get(HConnection.HBASE_CLIENT_CONNECTION_IMPL,
225280
ConnectionManager.HConnectionImplementation.class.getName());
226281
Class<?> clazz = null;

hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@
4545
import java.util.concurrent.atomic.AtomicBoolean;
4646
import java.util.concurrent.atomic.AtomicInteger;
4747

48+
import org.apache.commons.lang.StringUtils;
4849
import org.apache.commons.logging.Log;
4950
import org.apache.commons.logging.LogFactory;
5051
import org.apache.hadoop.conf.Configuration;
52+
import org.apache.hadoop.hbase.AuthFailedException;
5153
import org.apache.hadoop.hbase.DoNotRetryIOException;
5254
import org.apache.hadoop.hbase.HBaseConfiguration;
5355
import org.apache.hadoop.hbase.HConstants;
@@ -183,6 +185,7 @@
183185
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.UnassignRegionResponse;
184186
import org.apache.hadoop.hbase.regionserver.RegionServerStoppedException;
185187
import org.apache.hadoop.hbase.security.User;
188+
import org.apache.hadoop.hbase.security.User.SecureHadoopUser;
186189
import org.apache.hadoop.hbase.security.UserProvider;
187190
import org.apache.hadoop.hbase.util.Bytes;
188191
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
@@ -192,6 +195,7 @@
192195
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
193196
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
194197
import org.apache.hadoop.ipc.RemoteException;
198+
import org.apache.hadoop.security.UserGroupInformation;
195199
import org.apache.zookeeper.KeeperException;
196200

197201
import com.google.common.annotations.VisibleForTesting;
@@ -336,8 +340,32 @@ public static HConnection createConnection(Configuration conf) throws IOExceptio
336340
}
337341

338342
static ClusterConnection createConnectionInternal(Configuration conf) throws IOException {
343+
// UserProvider provider = UserProvider.instantiate(conf);
344+
// return createConnection(conf, false, null, provider.getCurrent());
339345
UserProvider provider = UserProvider.instantiate(conf);
340-
return createConnection(conf, false, null, provider.getCurrent());
346+
User currentUser = null;
347+
try {
348+
currentUser = provider.getCurrent();
349+
} catch (Exception e) {
350+
LOG.warn("Failed to get current user from configuration.", e);
351+
currentUser = null;
352+
}
353+
354+
if (currentUser == null) {
355+
currentUser = getCurrentUser();
356+
}
357+
358+
return createConnection(conf, false, null, currentUser);
359+
}
360+
361+
private static User getCurrentUser(){
362+
String currentUserName = System.getProperty("user.name");
363+
if(StringUtils.isBlank(currentUserName)){
364+
LOG.warn("The current user name is blank, and set it to hbase user.");
365+
currentUserName = "hbase";
366+
}
367+
368+
return new User.SecureHadoopUser(UserGroupInformation.createRemoteUser(currentUserName));
341369
}
342370

343371
/**
@@ -362,8 +390,21 @@ static ClusterConnection createConnectionInternal(Configuration conf) throws IOE
362390
*/
363391
public static HConnection createConnection(Configuration conf, ExecutorService pool)
364392
throws IOException {
393+
// UserProvider provider = UserProvider.instantiate(conf);
365394
UserProvider provider = UserProvider.instantiate(conf);
366-
return createConnection(conf, false, pool, provider.getCurrent());
395+
User currentUser = null;
396+
try {
397+
currentUser = provider.getCurrent();
398+
} catch (Exception e) {
399+
LOG.warn("Failed to get current user from configuration.", e);
400+
currentUser = null;
401+
}
402+
403+
if (currentUser == null) {
404+
currentUser = getCurrentUser();
405+
}
406+
407+
return createConnection(conf, false, pool, currentUser);
367408
}
368409

369410
/**
@@ -420,8 +461,21 @@ public static HConnection createConnection(Configuration conf, ExecutorService p
420461
@Deprecated
421462
static HConnection createConnection(final Configuration conf, final boolean managed)
422463
throws IOException {
464+
//UserProvider provider = UserProvider.instantiate(conf);
423465
UserProvider provider = UserProvider.instantiate(conf);
424-
return createConnection(conf, managed, null, provider.getCurrent());
466+
User currentUser = null;
467+
try {
468+
currentUser = provider.getCurrent();
469+
} catch (Exception e) {
470+
LOG.warn("Failed to get current user from configuration.", e);
471+
currentUser = null;
472+
}
473+
474+
if (currentUser == null) {
475+
currentUser = getCurrentUser();
476+
}
477+
478+
return createConnection(conf, managed, null, currentUser);
425479
}
426480

427481
@Deprecated
@@ -1555,6 +1609,11 @@ Object makeStub() throws IOException {
15551609
exceptionCaught = e;
15561610
} catch (ServiceException e) {
15571611
exceptionCaught = e;
1612+
String msg = e.getMessage();
1613+
if (msg.indexOf("AuthFailedException") != -1)
1614+
{
1615+
throw new AuthFailedException(msg);
1616+
}
15581617
}
15591618

15601619
throw new MasterNotRunningException(exceptionCaught);
@@ -1735,9 +1794,15 @@ public MasterKeepAliveConnection getKeepAliveMasterService()
17351794
MasterServiceStubMaker stubMaker = new MasterServiceStubMaker();
17361795
try {
17371796
this.masterServiceState.stub = stubMaker.makeStub();
1738-
} catch (MasterNotRunningException ex) {
1797+
}
1798+
catch(AuthFailedException ex1)
1799+
{
1800+
throw ex1;
1801+
}
1802+
catch (MasterNotRunningException ex) {
17391803
throw ex;
1740-
} catch (IOException e) {
1804+
}
1805+
catch (IOException e) {
17411806
// rethrow as MasterNotRunningException so that we can keep the method sig
17421807
throw new MasterNotRunningException(e);
17431808
}

0 commit comments

Comments
 (0)