Skip to content

Commit

Permalink
Introduce ClientRequestFilter.java: A New Plugin for Applying Request…
Browse files Browse the repository at this point in the history
… Headers

Merge additional headers into the client request in the AuthenticationFilter class.
Add test class "TestClientRequestFilterPlugin.java" to test the plugin
  • Loading branch information
SthuthiGhosh9400 committed Oct 15, 2024
1 parent b21f816 commit 9fa7ae2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@
import com.facebook.presto.spi.CoordinatorPlugin;
import com.facebook.presto.spi.Plugin;
import com.facebook.presto.spi.analyzer.AnalyzerProvider;
import com.facebook.presto.spi.analyzer.QueryPreparerProvider;
import com.facebook.presto.spi.classloader.ThreadContextClassLoader;
import com.facebook.presto.spi.connector.ConnectorFactory;
import com.facebook.presto.spi.eventlistener.EventListenerFactory;
import com.facebook.presto.spi.function.FunctionNamespaceManagerFactory;
import com.facebook.presto.spi.nodestatus.NodeStatusNotificationProviderFactory;
import com.facebook.presto.spi.plan.PlanCheckerProviderFactory;
import com.facebook.presto.spi.prerequisites.QueryPrerequisitesFactory;
import com.facebook.presto.spi.resourceGroups.ResourceGroupConfigurationManagerFactory;
import com.facebook.presto.spi.security.PasswordAuthenticatorFactory;
Expand Down Expand Up @@ -108,10 +106,8 @@ public class PluginManager
.add("com.facebook.drift.TApplicationException")
.build();

// TODO: To make CoordinatorPlugin loading compulsory when native execution is enabled.
private static final String COORDINATOR_PLUGIN_SERVICES_FILE = "META-INF/services/" + CoordinatorPlugin.class.getName();
private static final String PLUGIN_SERVICES_FILE = "META-INF/services/" + Plugin.class.getName();
private static final Logger log = Logger.get(PluginManager.class);

private final ConnectorManager connectorManager;
private final Metadata metadata;
private final ResourceGroupManager<?> resourceGroupManager;
Expand All @@ -133,7 +129,6 @@ public class PluginManager
private final HistoryBasedPlanStatisticsManager historyBasedPlanStatisticsManager;
private final TracerProviderManager tracerProviderManager;
private final AnalyzerProviderManager analyzerProviderManager;
private final QueryPreparerProviderManager queryPreparerProviderManager;
private final NodeStatusNotificationManager nodeStatusNotificationManager;
private final PlanCheckerProviderManager planCheckerProviderManager;
private final ClientRequestFilterManager clientRequestFilterManager;
Expand All @@ -146,7 +141,6 @@ public PluginManager(
Metadata metadata,
ResourceGroupManager<?> resourceGroupManager,
AnalyzerProviderManager analyzerProviderManager,
QueryPreparerProviderManager queryPreparerProviderManager,
AccessControlManager accessControlManager,
PasswordAuthenticatorManager passwordAuthenticatorManager,
EventListenerManager eventListenerManager,
Expand Down Expand Up @@ -190,7 +184,6 @@ public PluginManager(
this.historyBasedPlanStatisticsManager = requireNonNull(historyBasedPlanStatisticsManager, "historyBasedPlanStatisticsManager is null");
this.tracerProviderManager = requireNonNull(tracerProviderManager, "tracerProviderManager is null");
this.analyzerProviderManager = requireNonNull(analyzerProviderManager, "analyzerProviderManager is null");
this.queryPreparerProviderManager = requireNonNull(queryPreparerProviderManager, "queryPreparerProviderManager is null");
this.nodeStatusNotificationManager = requireNonNull(nodeStatusNotificationManager, "nodeStatusNotificationManager is null");
this.planCheckerProviderManager = requireNonNull(planCheckerProviderManager, "planCheckerProviderManager is null");
this.clientRequestFilterManager = requireNonNull(clientRequestFilterManager, "clientRequestFilterManager is null");
Expand Down Expand Up @@ -224,32 +217,23 @@ private void loadPlugin(String plugin)
log.info("-- Loading plugin %s --", plugin);
URLClassLoader pluginClassLoader = buildClassLoader(plugin);
try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(pluginClassLoader)) {
loadPlugin(pluginClassLoader, CoordinatorPlugin.class);
loadPlugin(pluginClassLoader, Plugin.class);
loadPlugin(pluginClassLoader);
}
log.info("-- Finished loading plugin %s --", plugin);
}

private void loadPlugin(URLClassLoader pluginClassLoader, Class<?> clazz)
private void loadPlugin(URLClassLoader pluginClassLoader)
{
ServiceLoader<?> serviceLoader = ServiceLoader.load(clazz, pluginClassLoader);
List<?> plugins = ImmutableList.copyOf(serviceLoader);
ServiceLoader<Plugin> serviceLoader = ServiceLoader.load(Plugin.class, pluginClassLoader);
List<Plugin> plugins = ImmutableList.copyOf(serviceLoader);

if (plugins.isEmpty()) {
log.warn("No service providers of type %s", clazz.getName());
log.warn("No service providers of type %s", Plugin.class.getName());
}

for (Object plugin : plugins) {
for (Plugin plugin : plugins) {
log.info("Installing %s", plugin.getClass().getName());
if (plugin instanceof Plugin) {
installPlugin((Plugin) plugin);
}
else if (plugin instanceof CoordinatorPlugin) {
installCoordinatorPlugin((CoordinatorPlugin) plugin);
}
else {
log.warn("Unknown plugin type: %s", plugin.getClass().getName());
}
installPlugin(plugin);
}
}

Expand Down
2 changes: 0 additions & 2 deletions presto-spi/src/main/java/com/facebook/presto/spi/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
import com.facebook.presto.common.type.ParametricType;
import com.facebook.presto.common.type.Type;
import com.facebook.presto.spi.analyzer.AnalyzerProvider;
import com.facebook.presto.spi.analyzer.QueryPreparerProvider;
import com.facebook.presto.spi.connector.ConnectorFactory;
import com.facebook.presto.spi.eventlistener.EventListenerFactory;
import com.facebook.presto.spi.function.FunctionNamespaceManagerFactory;
import com.facebook.presto.spi.nodestatus.NodeStatusNotificationProviderFactory;
import com.facebook.presto.spi.plan.PlanCheckerProviderFactory;
import com.facebook.presto.spi.prerequisites.QueryPrerequisitesFactory;
import com.facebook.presto.spi.resourceGroups.ResourceGroupConfigurationManagerFactory;
import com.facebook.presto.spi.security.PasswordAuthenticatorFactory;
Expand Down

0 comments on commit 9fa7ae2

Please sign in to comment.