org.elasticsearch.plugins.Plugin Java Examples

The following examples show how to use org.elasticsearch.plugins.Plugin. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TermsByQueryBenchmark.java    From siren-join with GNU Affero General Public License v3.0 6 votes vote down vote up
TermsByQueryBenchmark() {
  Settings settings = Settings.builder()
    .put(FilterJoinCache.SIREN_FILTERJOIN_CACHE_ENABLED, false)
    .put("index.engine.robin.refreshInterval", "-1")
    .put("path.home", "./target/elasticsearch-benchmark/home/")
    .put("node.local", true)
    .put(SETTING_NUMBER_OF_SHARDS, NUM_SHARDS)
    .put(SETTING_NUMBER_OF_REPLICAS, NUM_REPLICAS)
    .build();

  this.nodes = new MockNode[2];
  this.nodes[0] = new MockNode(Settings.builder().put(settings).put("name", "node1").build(),
          Version.CURRENT, Collections.<Class<? extends Plugin>>singletonList(SirenJoinPlugin.class)).start();
  this.nodes[1] = new MockNode(Settings.builder().put(settings).put("name", "node2").build(),
          Version.CURRENT, Collections.<Class<? extends Plugin>>singletonList(SirenJoinPlugin.class)).start();
  this.client = nodes[0].client();
  this.random = new Random(System.currentTimeMillis());
}
 
Example #2
Source File: FilterJoinBenchmark.java    From siren-join with GNU Affero General Public License v3.0 6 votes vote down vote up
FilterJoinBenchmark() {
  Settings settings = Settings.builder()
    .put(FilterJoinCache.SIREN_FILTERJOIN_CACHE_ENABLED, false)
    .put("index.engine.robin.refreshInterval", "-1")
    .put("path.home", "./target/elasticsearch-benchmark/home/")
    .put("node.local", true)
    .put(SETTING_NUMBER_OF_SHARDS, NUM_SHARDS)
    .put(SETTING_NUMBER_OF_REPLICAS, NUM_REPLICAS)
    .put(IndexCacheModule.QUERY_CACHE_EVERYTHING, true)
    .build();

  this.nodes = new MockNode[2];
  this.nodes[0] = new MockNode(Settings.builder().put(settings).put("name", "node1").build(),
          Version.CURRENT, Collections.<Class<? extends Plugin>>singletonList(SirenJoinPlugin.class)).start();
  this.nodes[1] = new MockNode(Settings.builder().put(settings).put("name", "node2").build(),
          Version.CURRENT, Collections.<Class<? extends Plugin>>singletonList(SirenJoinPlugin.class)).start();
  this.client = nodes[0].client();
  this.random = new Random(System.currentTimeMillis());
}
 
Example #3
Source File: ElasticsearchITest.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
public static void main(final String[] args) throws Exception {
  final Settings settings = Settings.builder()
    .put("path.home", ES_WORKING_DIR)
    .put("path.data", ES_WORKING_DIR + "/data")
    .put("path.logs", ES_WORKING_DIR + "/logs")
    .put("transport.type", "netty4")
    .put("http.type", "netty4")
    .put("cluster.name", clusterName)
    .put("http.port", HTTP_PORT)
    .put("transport.tcp.port", HTTP_TRANSPORT_PORT)
    .put("network.host", "127.0.0.1")
    .build();

  final Collection<Class<? extends Plugin>> classpathPlugins = Collections.singletonList(Netty4Plugin.class);
  try (final Node node = NodeFactory.makeNode(settings, classpathPlugins)) {
    node.start();
    runRestClient();
    runTransportClient();
  }

  TestUtil.checkSpan(new ComponentSpanCount("java-elasticsearch", 4));
}
 
Example #4
Source File: EmbeddedElasticsearch5.java    From baleen with Apache License 2.0 6 votes vote down vote up
public EmbeddedElasticsearch5(Path dataPath, String clusterName, int httpPort, int transportPort)
    throws NodeValidationException {
  this.clusterName = clusterName;
  this.httpPort = httpPort;
  this.transportPort = transportPort;
  this.dataPath = dataPath;

  // NB 'transport.type' is not 'local' as connecting via separate transport client
  Settings settings =
      Settings.builder()
          .put("path.home", dataPath.toString())
          .put("cluster.name", clusterName)
          .put("http.port", Integer.toString(httpPort))
          .put("transport.tcp.port", Integer.toString(transportPort))
          .put("http.enabled", true)
          .build();

  Collection<Class<? extends Plugin>> plugins = Collections.singletonList(Netty4Plugin.class);
  node = new PluginConfigurableNode(settings, plugins);
  node.start();
}
 
Example #5
Source File: NodeFactory.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
public static Node makeNode(final Settings settings, Collection<Class<? extends Plugin>> classpathPlugins) {
  final Environment environment = makeEnvironment(settings);
  try {
    for (final Constructor<?> constructor : Node.class.getDeclaredConstructors()) {
      if (Arrays.equals(constructor.getParameterTypes(), new Class[] {Environment.class, Collection.class}))
        return (Node)constructor.newInstance(environment, classpathPlugins);

      if (Arrays.equals(constructor.getParameterTypes(), new Class[] {Environment.class, Collection.class, boolean.class}))
        return (Node)constructor.newInstance(environment, classpathPlugins, false);
    }

    throw new IllegalStateException("Could not find compatible method: Node.<init>(...)");
  }
  catch (final IllegalAccessException | InstantiationException | InvocationTargetException e) {
    throw new RuntimeException(e);
  }
}
 
Example #6
Source File: Elasticsearch7SearchIndex.java    From vertexium with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static Collection<Class<? extends Plugin>> loadTransportClientPlugins(ElasticsearchSearchIndexConfiguration config) {
    return config.getEsPluginClassNames().stream()
        .map(pluginClassName -> {
            try {
                return (Class<? extends Plugin>) Class.forName(pluginClassName);
            } catch (ClassNotFoundException ex) {
                throw new VertexiumException("Could not load transport client plugin: " + pluginClassName, ex);
            }
        })
        .collect(Collectors.toList());
}
 
Example #7
Source File: CrateComponentLoader.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public Collection<Module> nodeModules() {
    List<Module> modules = Lists.newArrayList();
    for (Plugin plugin : plugins) {
        modules.addAll(plugin.nodeModules());
    }
    return modules;
}
 
Example #8
Source File: CrateComponentLoader.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public Collection<Class<? extends LifecycleComponent>> nodeServices() {
    List<Class<? extends LifecycleComponent>> services = Lists.newArrayList();
    for (Plugin plugin : plugins) {
        services.addAll(plugin.nodeServices());
    }
    return services;
}
 
Example #9
Source File: CrateComponentLoader.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private CrateComponentLoader(Settings settings) {
    ServiceLoader<CrateComponent> crateComponents = ServiceLoader.load(CrateComponent.class);
    plugins = new ArrayList<>();
    MapBuilder<Plugin, List<OnModuleReference>> onModuleReferences = MapBuilder.newMapBuilder();
    for (CrateComponent crateComponent : crateComponents) {
        logger.trace("Loading crateComponent: {}", crateComponent);
        Plugin plugin = crateComponent.createPlugin(settings);
        plugins.add(plugin);
        List<OnModuleReference> list = Lists.newArrayList();
        for (Method method : plugin.getClass().getDeclaredMethods()) {
            if (!method.getName().equals("onModule")) {
                continue;
            }
            if (method.getParameterTypes().length == 0 || method.getParameterTypes().length > 1) {
                logger.warn("Plugin: {} implementing onModule with no parameters or more than one parameter", plugin.name());
                continue;
            }
            Class moduleClass = method.getParameterTypes()[0];
            if (!Module.class.isAssignableFrom(moduleClass)) {
                logger.warn("Plugin: {} implementing onModule by the type is not of Module type {}", plugin.name(), moduleClass);
                continue;
            }
            method.setAccessible(true);
            //noinspection unchecked
            list.add(new OnModuleReference(moduleClass, method));
        }
        if (!list.isEmpty()) {
            onModuleReferences.put(plugin, list);
        }
    }
    this.onModuleReferences = onModuleReferences.immutableMap();
}
 
Example #10
Source File: CrateComponentLoader.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public Collection<Module> shardModules(Settings indexSettings) {
    List<Module> modules = Lists.newArrayList();
    for (Plugin plugin : plugins) {
        modules.addAll(plugin.shardModules(indexSettings));
    }
    return modules;
}
 
Example #11
Source File: CrateComponentLoader.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public Settings additionalSettings() {
    Settings.Builder builder = Settings.settingsBuilder();
    for (Plugin plugin : plugins) {
        builder.put(plugin.additionalSettings());
    }
    return builder.build();
}
 
Example #12
Source File: Elasticsearch7SearchIndex.java    From vertexium with Apache License 2.0 5 votes vote down vote up
private static Client createTransportClient(ElasticsearchSearchIndexConfiguration config) {
    Settings settings = tryReadSettingsFromFile(config);
    if (settings == null) {
        Settings.Builder settingsBuilder = Settings.builder();
        if (config.getClusterName() != null) {
            settingsBuilder.put("cluster.name", config.getClusterName());
        }
        for (Map.Entry<String, String> esSetting : config.getEsSettings().entrySet()) {
            settingsBuilder.put(esSetting.getKey(), esSetting.getValue());
        }
        settings = settingsBuilder.build();
    }
    Collection<Class<? extends Plugin>> plugins = loadTransportClientPlugins(config);
    Client transportClient = config.getXpackEnabled() ?
        new org.elasticsearch.xpack.client.PreBuiltXPackTransportClient(settings, plugins) :
        new org.elasticsearch.transport.client.PreBuiltTransportClient(settings, plugins);
    for (String esLocation : config.getEsLocations()) {
        String[] locationSocket = esLocation.split(":");
        String hostname;
        int port;
        if (locationSocket.length == 2) {
            hostname = locationSocket[0];
            port = Integer.parseInt(locationSocket[1]);
        } else if (locationSocket.length == 1) {
            hostname = locationSocket[0];
            port = config.getPort();
        } else {
            throw new VertexiumException("Invalid elastic search location: " + esLocation);
        }
        InetAddress host;
        try {
            host = InetAddress.getByName(hostname);
        } catch (UnknownHostException ex) {
            throw new VertexiumException("Could not resolve host: " + hostname, ex);
        }
        ((org.elasticsearch.client.transport.TransportClient) transportClient).addTransportAddress(new TransportAddress(new InetSocketAddress(host, port)));
    }
    return transportClient;
}
 
Example #13
Source File: Elasticsearch5SearchIndex.java    From vertexium with Apache License 2.0 5 votes vote down vote up
private static TransportClient createTransportClient(ElasticsearchSearchIndexConfiguration config) {
    Settings settings = tryReadSettingsFromFile(config);
    if (settings == null) {
        Settings.Builder settingsBuilder = Settings.builder();
        if (config.getClusterName() != null) {
            settingsBuilder.put("cluster.name", config.getClusterName());
        }
        for (Map.Entry<String, String> esSetting : config.getEsSettings().entrySet()) {
            settingsBuilder.put(esSetting.getKey(), esSetting.getValue());
        }
        settings = settingsBuilder.build();
    }
    Collection<Class<? extends Plugin>> plugins = loadTransportClientPlugins(config);
    TransportClient transportClient = new PreBuiltTransportClient(settings, plugins);
    for (String esLocation : config.getEsLocations()) {
        String[] locationSocket = esLocation.split(":");
        String hostname;
        int port;
        if (locationSocket.length == 2) {
            hostname = locationSocket[0];
            port = Integer.parseInt(locationSocket[1]);
        } else if (locationSocket.length == 1) {
            hostname = locationSocket[0];
            port = config.getPort();
        } else {
            throw new VertexiumException("Invalid elastic search location: " + esLocation);
        }
        InetAddress host;
        try {
            host = InetAddress.getByName(hostname);
        } catch (UnknownHostException ex) {
            throw new VertexiumException("Could not resolve host: " + hostname, ex);
        }
        transportClient.addTransportAddress(new InetSocketTransportAddress(host, port));
    }
    return transportClient;
}
 
Example #14
Source File: Elasticsearch5SearchIndex.java    From vertexium with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static Collection<Class<? extends Plugin>> loadTransportClientPlugins(ElasticsearchSearchIndexConfiguration config) {
    return config.getEsPluginClassNames().stream()
        .map(pluginClassName -> {
            try {
                return (Class<? extends Plugin>) Class.forName(pluginClassName);
            } catch (ClassNotFoundException ex) {
                throw new VertexiumException("Could not load transport client plugin: " + pluginClassName, ex);
            }
        })
        .collect(Collectors.toList());
}
 
Example #15
Source File: EmbeddedElasticSearchV6.java    From conductor with Apache License 2.0 5 votes vote down vote up
public PluginConfigurableNode(Settings preparedSettings, Collection<Class<? extends Plugin>> classpathPlugins) {
    super(InternalSettingsPreparer.prepareEnvironment(preparedSettings, null), classpathPlugins, false);
}
 
Example #16
Source File: LocalNode.java    From core-ng-project with Apache License 2.0 5 votes vote down vote up
private static List<Class<? extends Plugin>> plugins() {
    return List.of(ReindexPlugin.class,
            Netty4Plugin.class,
            MapperExtrasPlugin.class,  // for scaled_float type
            PainlessPlugin.class,
            CommonAnalysisPlugin.class);  // for stemmer analysis
}
 
Example #17
Source File: ElasticsearchSailTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
	return Arrays.asList(ReindexPlugin.class);
}
 
Example #18
Source File: ContentAuthPluginLocator.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public Class<? extends Plugin> pluginClass() {
  return ContentAuthPlugin.class;
}
 
Example #19
Source File: ElasticsearchIOTest.java    From beam with Apache License 2.0 4 votes vote down vote up
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
  ArrayList<Class<? extends Plugin>> plugins = new ArrayList<>();
  plugins.add(Netty4Plugin.class);
  return plugins;
}
 
Example #20
Source File: PluginUsingNode.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
public PluginUsingNode(final Settings preparedSettings, Collection<Class<? extends Plugin>> plugins) {
  super(InternalSettingsPreparer.prepareEnvironment(preparedSettings, null), Version.CURRENT, plugins);
}
 
Example #21
Source File: NodeProvider.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
private Collection<Class<? extends Plugin>> deployedPluginClasses() {
  return pluginLocators.stream().map(PluginLocator::pluginClass).collect(Collectors.toList());
}
 
Example #22
Source File: EmbeddedElasticSearchV5.java    From conductor with Apache License 2.0 4 votes vote down vote up
public PluginConfigurableNode(Settings preparedSettings, Collection<Class<? extends Plugin>> classpathPlugins) {
    super(InternalSettingsPreparer.prepareEnvironment(preparedSettings, null), classpathPlugins);
}
 
Example #23
Source File: ElasticsearchSailTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected Collection<Class<? extends Plugin>> transportClientPlugins() {
	return Arrays.asList(ReindexPlugin.class);
}
 
Example #24
Source File: ElasticsearchIndexTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
	return Arrays.asList(ReindexPlugin.class);
}
 
Example #25
Source File: ElasticsearchIndexTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected Collection<Class<? extends Plugin>> transportClientPlugins() {
	return Arrays.asList(ReindexPlugin.class);
}
 
Example #26
Source File: ElasticsearchSailGeoSPARQLTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
	return Arrays.asList(ReindexPlugin.class);
}
 
Example #27
Source File: PluginEnabledNode.java    From elasticsearch-shield-kerberos-realm with Apache License 2.0 4 votes vote down vote up
public PluginEnabledNode(Settings preparedSettings, Collection<Class<? extends Plugin>> classpathPlugins) {
    super(InternalSettingsPreparer.prepareEnvironment(preparedSettings, null), Version.CURRENT, classpathPlugins);
}
 
Example #28
Source File: ElasticsearchSailIndexedPropertiesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
	return Arrays.asList(ReindexPlugin.class);
}
 
Example #29
Source File: ElasticsearchSailIndexedPropertiesTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected Collection<Class<? extends Plugin>> transportClientPlugins() {
	return Arrays.asList(ReindexPlugin.class);
}
 
Example #30
Source File: TransportClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
/**
 * Add the given plugin to the client when it is created.
 */
public Builder addPlugin(Class<? extends Plugin> pluginClass) {
    pluginClasses.add(pluginClass);
    return this;
}