Skip to content

Commit

Permalink
Corrected code
Browse files Browse the repository at this point in the history
  • Loading branch information
SthuthiGhosh9400 committed Oct 15, 2024
1 parent 9fa7ae2 commit d797300
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@
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 @@ -106,8 +108,10 @@ 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 @@ -129,6 +133,7 @@ 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 @@ -141,6 +146,7 @@ public PluginManager(
Metadata metadata,
ResourceGroupManager<?> resourceGroupManager,
AnalyzerProviderManager analyzerProviderManager,
QueryPreparerProviderManager queryPreparerProviderManager,
AccessControlManager accessControlManager,
PasswordAuthenticatorManager passwordAuthenticatorManager,
EventListenerManager eventListenerManager,
Expand Down Expand Up @@ -184,6 +190,7 @@ 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 @@ -217,23 +224,32 @@ private void loadPlugin(String plugin)
log.info("-- Loading plugin %s --", plugin);
URLClassLoader pluginClassLoader = buildClassLoader(plugin);
try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(pluginClassLoader)) {
loadPlugin(pluginClassLoader);
loadPlugin(pluginClassLoader, CoordinatorPlugin.class);
loadPlugin(pluginClassLoader, Plugin.class);
}
log.info("-- Finished loading plugin %s --", plugin);
}

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

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

for (Plugin plugin : plugins) {
for (Object plugin : plugins) {
log.info("Installing %s", plugin.getClass().getName());
installPlugin(plugin);
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());
}
}
}

Expand Down
2 changes: 2 additions & 0 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,10 +17,12 @@
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 d797300

Please sign in to comment.