ndimiduk commented on code in PR #5972:
URL: https://github.com/apache/hbase/pull/5972#discussion_r1634487660


##########
hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestCopyTableToPeerClusterWithClusterKey.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * 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.hadoop.hbase.mapreduce;
+
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.testclassification.LargeTests;
+import org.apache.hadoop.hbase.testclassification.MapReduceTests;
+import org.junit.ClassRule;
+import org.junit.experimental.categories.Category;
+
+@Category({ MapReduceTests.class, LargeTests.class })
+public class TestCopyTableToPeerClusterWithClusterKey extends 
CopyTableToPeerClusterTestBase {

Review Comment:
   Oof. It would be nice if we could verify this "simple" change without 
needing to actually run these map-reduce jobs. But yes, I understand why you've 
added them.



##########
hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/TableOutputFormat.java:
##########
@@ -91,6 +115,21 @@ public class TableOutputFormat<KEY> extends 
OutputFormat<KEY, Mutation> implemen
   /** The configuration. */
   private Configuration conf = null;
 
+  private static Connection createConnection(Configuration conf) throws 
IOException {
+    String outputCluster = conf.get(OUTPUT_CLUSTER);
+    if (!StringUtils.isBlank(outputCluster)) {
+      URI uri;
+      try {
+        uri = new URI(outputCluster);
+      } catch (URISyntaxException e) {
+        throw new IOException("malformed connection uri: " + outputCluster, e);

Review Comment:
   nit: add the configuration key to the error message to help the user track 
down the issue? There's a couple places where this pattern repeats.



##########
hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestTableMapReduceUtil.java:
##########
@@ -287,4 +288,43 @@ public void testInitCredentialsForCluster4() throws 
Exception {
       kdc.stop();
     }
   }
+
+  @Test
+  @SuppressWarnings("unchecked")
+  public void testInitCredentialsForClusterUri() throws Exception {
+    HBaseTestingUtil util1 = new HBaseTestingUtil();
+    HBaseTestingUtil util2 = new HBaseTestingUtil();
+
+    File keytab = new File(util1.getDataTestDir("keytab").toUri().getPath());
+    MiniKdc kdc = util1.setupMiniKdc(keytab);
+    try {
+      String username = UserGroupInformation.getLoginUser().getShortUserName();
+      String userPrincipal = username + "/localhost";
+      kdc.createPrincipal(keytab, userPrincipal, HTTP_PRINCIPAL);
+      loginUserFromKeytab(userPrincipal + '@' + kdc.getRealm(), 
keytab.getAbsolutePath());
+
+      try (Closeable util1Closeable = startSecureMiniCluster(util1, kdc, 
userPrincipal);

Review Comment:
   nit: call these `ignored` and `ignored1` so that IntelliJ won't warn about 
them being unused.



##########
hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestTableMapReduceUtil.java:
##########
@@ -287,4 +288,43 @@ public void testInitCredentialsForCluster4() throws 
Exception {
       kdc.stop();
     }
   }
+
+  @Test
+  @SuppressWarnings("unchecked")
+  public void testInitCredentialsForClusterUri() throws Exception {
+    HBaseTestingUtil util1 = new HBaseTestingUtil();
+    HBaseTestingUtil util2 = new HBaseTestingUtil();
+
+    File keytab = new File(util1.getDataTestDir("keytab").toUri().getPath());
+    MiniKdc kdc = util1.setupMiniKdc(keytab);
+    try {
+      String username = UserGroupInformation.getLoginUser().getShortUserName();
+      String userPrincipal = username + "/localhost";
+      kdc.createPrincipal(keytab, userPrincipal, HTTP_PRINCIPAL);
+      loginUserFromKeytab(userPrincipal + '@' + kdc.getRealm(), 
keytab.getAbsolutePath());
+
+      try (Closeable util1Closeable = startSecureMiniCluster(util1, kdc, 
userPrincipal);
+        Closeable util2Closeable = startSecureMiniCluster(util2, kdc, 
userPrincipal)) {
+        Configuration conf1 = util1.getConfiguration();
+        Job job = Job.getInstance(conf1);
+
+        // use Configuration from util1 and URI from util2, to make sure that 
we use the URI instead
+        // of rely on the Configuration
+        TableMapReduceUtil.initCredentialsForCluster(job, 
util1.getConfiguration(),
+          new URI(util2.getRpcConnnectionURI()));
+
+        Credentials credentials = job.getCredentials();
+        Collection<Token<? extends TokenIdentifier>> tokens = 
credentials.getAllTokens();
+        assertEquals(1, tokens.size());
+
+        String clusterId = 
ZKClusterId.readClusterIdZNode(util2.getZooKeeperWatcher());
+        Token<AuthenticationTokenIdentifier> tokenForCluster =
+          (Token<AuthenticationTokenIdentifier>) credentials.getToken(new 
Text(clusterId));
+        assertEquals(userPrincipal + '@' + kdc.getRealm(),
+          tokenForCluster.decodeIdentifier().getUsername());
+      }
+    } finally {
+      kdc.stop();

Review Comment:
   I'm surprised to see that `MiniKdc` is not `AutoCloseable`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to