You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by el...@apache.org on 2017/09/07 19:26:04 UTC

[2/4] phoenix git commit: PHOENIX-4168 Pluggable Remote User Extraction

PHOENIX-4168 Pluggable Remote User Extraction

Adds factory for creating RemoteUserExtractor instances. The factory
can be overridden using ServiceLoader. The default factory creates
PhoenixRemoteUserExtractor instances.

Signed-off-by: Josh Elser <el...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/bdb6a14a
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/bdb6a14a
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/bdb6a14a

Branch: refs/heads/4.x-HBase-1.2
Commit: bdb6a14a11017936ce23d6762f97d1475324cbfd
Parents: 5cf07c4
Author: Alex Araujo <al...@gmail.com>
Authored: Wed Sep 6 13:33:27 2017 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Thu Sep 7 14:50:20 2017 -0400

----------------------------------------------------------------------
 .../phoenix/queryserver/server/QueryServer.java | 13 ++++++-
 .../server/RemoteUserExtractorFactory.java      | 36 ++++++++++++++++++++
 .../server/RemoteUserExtractorFactoryTest.java  | 35 +++++++++++++++++++
 3 files changed, 83 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/bdb6a14a/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/QueryServer.java
----------------------------------------------------------------------
diff --git a/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/QueryServer.java b/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/QueryServer.java
index 21eb2ef..288e4f5 100644
--- a/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/QueryServer.java
+++ b/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/QueryServer.java
@@ -51,6 +51,7 @@ import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.query.QueryServicesOptions;
 import org.apache.phoenix.loadbalancer.service.LoadBalanceZookeeperConf;
 import org.apache.phoenix.queryserver.register.Registry;
+import org.apache.phoenix.util.InstanceResolver;
 
 import java.io.File;
 import java.lang.management.ManagementFactory;
@@ -373,10 +374,20 @@ public final class QueryServer extends Configured implements Tool, Runnable {
   public void setRemoteUserExtractorIfNecessary(HttpServer.Builder builder, Configuration conf) {
     if (conf.getBoolean(QueryServices.QUERY_SERVER_WITH_REMOTEUSEREXTRACTOR_ATTRIB,
             QueryServicesOptions.DEFAULT_QUERY_SERVER_WITH_REMOTEUSEREXTRACTOR)) {
-      builder.withRemoteUserExtractor(new PhoenixRemoteUserExtractor(conf));
+      builder.withRemoteUserExtractor(createRemoteUserExtractor(conf));
     }
   }
 
+  private static final RemoteUserExtractorFactory DEFAULT_USER_EXTRACTOR =
+    new RemoteUserExtractorFactory.RemoteUserExtractorFactoryImpl();
+
+  @VisibleForTesting
+  RemoteUserExtractor createRemoteUserExtractor(Configuration conf) {
+    RemoteUserExtractorFactory factory =
+        InstanceResolver.getSingleton(RemoteUserExtractorFactory.class, DEFAULT_USER_EXTRACTOR);
+    return factory.createRemoteUserExtractor(conf);
+  }
+
   /**
    * Use the correctly way to extract end user.
    */

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bdb6a14a/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/RemoteUserExtractorFactory.java
----------------------------------------------------------------------
diff --git a/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/RemoteUserExtractorFactory.java b/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/RemoteUserExtractorFactory.java
new file mode 100644
index 0000000..ff5e0d2
--- /dev/null
+++ b/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/RemoteUserExtractorFactory.java
@@ -0,0 +1,36 @@
+/*
+ * 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.phoenix.queryserver.server;
+
+import org.apache.calcite.avatica.server.RemoteUserExtractor;
+import org.apache.hadoop.conf.Configuration;
+
+/**
+ * Creates remote user extractors.
+ */
+public interface RemoteUserExtractorFactory {
+
+  RemoteUserExtractor createRemoteUserExtractor(Configuration conf);
+
+  class RemoteUserExtractorFactoryImpl implements RemoteUserExtractorFactory {
+    @Override
+    public RemoteUserExtractor createRemoteUserExtractor(Configuration conf) {
+      return new QueryServer.PhoenixRemoteUserExtractor(conf);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bdb6a14a/phoenix-queryserver/src/test/java/org/apache/phoenix/queryserver/server/RemoteUserExtractorFactoryTest.java
----------------------------------------------------------------------
diff --git a/phoenix-queryserver/src/test/java/org/apache/phoenix/queryserver/server/RemoteUserExtractorFactoryTest.java b/phoenix-queryserver/src/test/java/org/apache/phoenix/queryserver/server/RemoteUserExtractorFactoryTest.java
new file mode 100644
index 0000000..975ee26
--- /dev/null
+++ b/phoenix-queryserver/src/test/java/org/apache/phoenix/queryserver/server/RemoteUserExtractorFactoryTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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.phoenix.queryserver.server;
+
+import org.apache.calcite.avatica.server.RemoteUserExtractor;
+import org.apache.hadoop.conf.Configuration;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class RemoteUserExtractorFactoryTest {
+
+  @Test
+  public void testProvidesDefaultFactory() {
+    QueryServer queryServer = new QueryServer();
+    RemoteUserExtractor extractor = queryServer.createRemoteUserExtractor(new Configuration());
+    Assert.assertTrue(
+      "Not an instance of PhoenixRemoteUserExtractor: " + extractor.getClass().getName(),
+      extractor instanceof QueryServer.PhoenixRemoteUserExtractor);
+  }
+}