Java Code Examples for org.elasticsearch.plugins.Plugin

The following examples show how to use org.elasticsearch.plugins.Plugin. These examples are extracted from open source projects. 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 Project: java-specialagent   Source File: NodeFactory.java    License: 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 2
Source Project: java-specialagent   Source File: ElasticsearchITest.java    License: 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 3
Source Project: baleen   Source File: EmbeddedElasticsearch5.java    License: 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 4
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 5
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 6
Source Project: Elasticsearch   Source File: CrateComponentLoader.java    License: 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 7
Source Project: Elasticsearch   Source File: CrateComponentLoader.java    License: 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 Project: Elasticsearch   Source File: CrateComponentLoader.java    License: 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 Project: Elasticsearch   Source File: CrateComponentLoader.java    License: 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 10
Source Project: Elasticsearch   Source File: CrateComponentLoader.java    License: 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 11
Source Project: conductor   Source File: EmbeddedElasticSearchV6.java    License: 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 12
Source Project: vertexium   Source File: Elasticsearch7SearchIndex.java    License: 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 Project: vertexium   Source File: Elasticsearch7SearchIndex.java    License: 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 14
Source Project: vertexium   Source File: Elasticsearch5SearchIndex.java    License: 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 15
Source Project: vertexium   Source File: Elasticsearch5SearchIndex.java    License: 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 16
Source Project: core-ng-project   Source File: LocalNode.java    License: 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
public TransportClientImpl(Settings settings, Collection<Class<? extends Plugin>> plugins) {
	super(settings, plugins);
}
 
Example 18
Source Project: metron   Source File: ElasticSearchComponent.java    License: Apache License 2.0 4 votes vote down vote up
private TestNode(Settings preparedSettings,
    Collection<Class<? extends Plugin>> classpathPlugins) {
  super(InternalSettingsPreparer.prepareEnvironment(preparedSettings, null), classpathPlugins);
}
 
Example 19
protected static Collection<Class<? extends Plugin>> asCollection(Class<? extends Plugin>... plugins) {
	return Arrays.asList(plugins);
}
 
Example 20
public PluginNode(Settings settings) {
	super(InternalSettingsPreparer.prepareEnvironment(settings, null), Collections.<Class<? extends Plugin>>singletonList(Netty3Plugin.class));
}
 
Example 21
public PluginNode(Settings settings) {
	super(InternalSettingsPreparer.prepareEnvironment(settings, null), Collections.<Class<? extends Plugin>>singletonList(Netty4Plugin.class));
}
 
Example 22
public PluginNode(Settings settings) {
	super(InternalSettingsPreparer.prepareEnvironment(settings, null), Collections.<Class<? extends Plugin>>singletonList(Netty3Plugin.class));
}
 
Example 23
public PluginNode(Settings settings) {
	super(InternalSettingsPreparer.prepareEnvironment(settings, null), Collections.<Class<? extends Plugin>>singletonList(Netty4Plugin.class));
}
 
Example 24
Source Project: Quicksql   Source File: EmbeddedElasticsearchNode.java    License: MIT License 4 votes vote down vote up
private LocalNode(Settings settings, Collection<Class<? extends Plugin>> classpathPlugins) {
  super(InternalSettingsPreparer.prepareEnvironment(settings, null),
      classpathPlugins);
}
 
Example 25
Source Project: Quicksql   Source File: EmbeddedElasticsearchNode.java    License: MIT License 4 votes vote down vote up
private LocalNode(Settings settings, Collection<Class<? extends Plugin>> classpathPlugins) {
    super(InternalSettingsPreparer.prepareEnvironment(settings, null), classpathPlugins);
}
 
Example 26
Source Project: deprecated-security-ssl   Source File: PluginAwareNode.java    License: Apache License 2.0 4 votes vote down vote up
@SafeVarargs
public PluginAwareNode(final Settings preparedSettings, final Class<? extends Plugin>... plugins) {
    super(InternalSettingsPreparer.prepareEnvironment(preparedSettings, null), Arrays.asList(plugins), true);
}
 
Example 27
Source Project: deprecated-security-ssl   Source File: AbstractUnitTest.java    License: Apache License 2.0 4 votes vote down vote up
protected Collection<Class<? extends Plugin>> asCollection(Class<? extends Plugin>... plugins) {
    return Arrays.asList(plugins);
}
 
Example 28
Source Project: deprecated-security-ssl   Source File: AbstractUnitTest.java    License: Apache License 2.0 4 votes vote down vote up
public TransportClientImpl(Settings settings, Collection<Class<? extends Plugin>> plugins) {
    super(settings, plugins);
}
 
Example 29
Source Project: deprecated-security-ssl   Source File: AbstractUnitTest.java    License: Apache License 2.0 4 votes vote down vote up
public TransportClientImpl(Settings settings, Settings defaultSettings, Collection<Class<? extends Plugin>> plugins) {
    super(settings, defaultSettings, plugins, null);
}
 
Example 30
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
    return Collections.singletonList(AnomalyDetectorPlugin.class);
}