public void run() throws Exception { try (TestingPrestoServer server = new TestingPrestoServer()) { for (String pluginClass : options.getPluginClassNames()) { Plugin plugin = (Plugin) Class.forName(pluginClass).newInstance(); server.installPlugin(plugin); } for (Catalog catalog : options.getCatalogs()) { server.createCatalog(catalog.getCatalogName(), catalog.getConnectorName()); } System.out.println(server.getAddress()); waitForInterruption(); } }
public static Set<String> discoverPlugins(Artifact artifact, ClassLoader classLoader) throws IOException { if (!artifact.getExtension().equals("presto-plugin")) { throw new RuntimeException("Unexpected extension for main artifact: " + artifact); } File file = artifact.getFile(); if (!file.getPath().endsWith("/target/classes")) { throw new RuntimeException("Unexpected file for main artifact: " + file); } if (!file.isDirectory()) { throw new RuntimeException("Main artifact file is not a directory: " + file); } if (new File(file, SERVICES_FILE).exists()) { return ImmutableSet.of(); } return listClasses(file.toPath()).stream() .filter(name -> classInterfaces(name, classLoader).contains(Plugin.class.getName())) .collect(toImmutableSet()); }
@SuppressWarnings("unchecked") private static <T extends Plugin> T loadPlugin(Class<T> clazz) { for (Plugin plugin : ServiceLoader.load(Plugin.class)) { if (clazz.isInstance(plugin)) { return (T) plugin; } } throw new AssertionError("did not find plugin: " + clazz.getName()); }
@Override public void installPlugin(Plugin plugin) { long start = System.nanoTime(); for (TestingPrestoServer server : servers) { server.installPlugin(plugin); } log.info("Installed plugin %s in %s", plugin.getClass().getSimpleName(), nanosSince(start).convertToMostSuccinctTimeUnit()); }
@Test public void testCreateConnector() throws Exception { Plugin plugin = new PostgreSqlPlugin(); ConnectorFactory factory = getOnlyElement(plugin.getServices(ConnectorFactory.class)); factory.create("test", ImmutableMap.of("connection-url", "test")); }
private void loadPlugin(URLClassLoader pluginClassLoader) throws Exception { 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", Plugin.class.getName()); } for (Plugin plugin : plugins) { log.info("Installing %s", plugin.getClass().getName()); installPlugin(plugin); } }
@Test public void testCreateConnector() throws Exception { Plugin plugin = new MySqlPlugin(); ConnectorFactory factory = getOnlyElement(plugin.getServices(ConnectorFactory.class)); factory.create("test", ImmutableMap.of("connection-url", "test")); }
public void installPlugin(Plugin plugin) { server.installPlugin(plugin); }
public void installPlugin(Plugin plugin) { pluginManager.installPlugin(plugin); }
@Override public void installPlugin(Plugin plugin) { throw new UnsupportedOperationException(); }
void installPlugin(Plugin plugin);