Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move vector tile implementation to its own module #73562

Merged
merged 3 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 0 additions & 101 deletions x-pack/plugin/spatial/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.elasticsearch.gradle.internal.info.BuildParams;

apply plugin: 'elasticsearch.internal-es-plugin'
apply plugin: 'elasticsearch.internal-cluster-test'
apply plugin: 'elasticsearch.yaml-rest-test'
Expand All @@ -16,80 +14,9 @@ dependencies {
compileOnly project(path: xpackModule('core'))
testImplementation(testArtifact(project(xpackModule('core'))))
yamlRestTestImplementation(testArtifact(project(xpackModule('core'))))
api project(path: ':modules:geo')
restTestConfig project(path: ':modules:geo', configuration: 'restTests')
api "com.wdtinc:mapbox-vector-tile:3.1.0"
api "com.google.protobuf:protobuf-java:3.14.0"
yamlRestTestImplementation("com.wdtinc:mapbox-vector-tile:3.1.0")
yamlRestTestImplementation("com.google.protobuf:protobuf-java:3.14.0")
}

restResources {
restApi {
include '_common', 'bulk', 'indices', 'index', 'search', 'xpack'
}
restTests {
includeCore 'geo_shape'
}
}

testClusters.all {
setting 'xpack.license.self_generated.type', 'trial'
testDistribution = 'DEFAULT'
setting 'xpack.security.enabled', 'false'
if (BuildParams.isSnapshotBuild() == false) {
systemProperty 'es.vector_tile_feature_flag_registered', 'true'
}
}

tasks.named("test").configure {
if (BuildParams.isSnapshotBuild() == false) {
systemProperty 'es.vector_tile_feature_flag_registered', 'true'
}
}

tasks.named("thirdPartyAudit").configure {
ignoreViolations(
// uses internal java api: sun.misc.Unsafe
'com.google.protobuf.UnsafeUtil',
'com.google.protobuf.MessageSchema',
'com.google.protobuf.UnsafeUtil$1',
'com.google.protobuf.UnsafeUtil$Android32MemoryAccessor',
'com.google.protobuf.UnsafeUtil$Android64MemoryAccessor',
'com.google.protobuf.UnsafeUtil$JvmMemoryAccessor',
'com.google.protobuf.UnsafeUtil$MemoryAccessor'
)

ignoreMissingClasses(
'org.slf4j.Logger',
'org.slf4j.LoggerFactory'
)
}

import org.elasticsearch.gradle.internal.info.BuildParams;

apply plugin: 'elasticsearch.esplugin'
apply plugin: 'elasticsearch.internal-cluster-test'
apply plugin: 'elasticsearch.yaml-rest-test'
apply plugin: 'elasticsearch.yaml-rest-compat-test'

esplugin {
name 'spatial'
description 'A plugin for Basic Spatial features'
classname 'org.elasticsearch.xpack.spatial.SpatialPlugin'
extendedPlugins = ['x-pack-core']
}

dependencies {
compileOnly project(path: xpackModule('core'))
testImplementation(testArtifact(project(xpackModule('core'))))
yamlRestTestImplementation(testArtifact(project(xpackModule('core'))))
api project(path: ':modules:geo')
restTestConfig project(path: ':modules:geo', configuration: 'restTests')
api "com.wdtinc:mapbox-vector-tile:3.1.0"
api "com.google.protobuf:protobuf-java:3.14.0"
yamlRestTestImplementation("com.wdtinc:mapbox-vector-tile:3.1.0")
yamlRestTestImplementation("com.google.protobuf:protobuf-java:3.14.0")
}

restResources {
Expand All @@ -105,32 +32,4 @@ testClusters.all {
setting 'xpack.license.self_generated.type', 'trial'
testDistribution = 'DEFAULT'
setting 'xpack.security.enabled', 'false'
if (BuildParams.isSnapshotBuild() == false) {
systemProperty 'es.vector_tile_feature_flag_registered', 'true'
}
}

tasks.named("test").configure {
if (BuildParams.isSnapshotBuild() == false) {
systemProperty 'es.vector_tile_feature_flag_registered', 'true'
}
}

tasks.named("thirdPartyAudit").configure {
ignoreViolations(
// uses internal java api: sun.misc.Unsafe
'com.google.protobuf.UnsafeUtil',
'com.google.protobuf.MessageSchema',
'com.google.protobuf.UnsafeUtil$1',
'com.google.protobuf.UnsafeUtil$Android32MemoryAccessor',
'com.google.protobuf.UnsafeUtil$Android64MemoryAccessor',
'com.google.protobuf.UnsafeUtil$JvmMemoryAccessor',
'com.google.protobuf.UnsafeUtil$MemoryAccessor'
)

ignoreMissingClasses(
'org.slf4j.Logger',
'org.slf4j.LoggerFactory'
)
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,8 @@
*/
package org.elasticsearch.xpack.spatial;

import org.elasticsearch.Build;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.IndexScopedSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.common.xcontent.ContextParser;
import org.elasticsearch.geo.GeoPlugin;
import org.elasticsearch.index.mapper.Mapper;
Expand All @@ -25,8 +18,6 @@
import org.elasticsearch.plugins.IngestPlugin;
import org.elasticsearch.plugins.MapperPlugin;
import org.elasticsearch.plugins.SearchPlugin;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestHandler;
import org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGridAggregationBuilder;
import org.elasticsearch.search.aggregations.bucket.geogrid.GeoTileGridAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.CardinalityAggregationBuilder;
Expand All @@ -36,8 +27,6 @@
import org.elasticsearch.search.aggregations.metrics.ValueCountAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.ValueCountAggregator;
import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry;
import org.elasticsearch.threadpool.ExecutorBuilder;
import org.elasticsearch.threadpool.FixedExecutorBuilder;
import org.elasticsearch.xpack.core.XPackPlugin;
import org.elasticsearch.xpack.core.action.XPackInfoFeatureAction;
import org.elasticsearch.xpack.core.action.XPackUsageFeatureAction;
Expand All @@ -55,8 +44,6 @@
import org.elasticsearch.xpack.spatial.ingest.CircleProcessor;
import org.elasticsearch.xpack.spatial.search.aggregations.GeoLineAggregationBuilder;
import org.elasticsearch.xpack.spatial.search.aggregations.InternalGeoLine;
import org.elasticsearch.xpack.spatial.search.aggregations.InternalVectorTile;
import org.elasticsearch.xpack.spatial.search.aggregations.VectorTileAggregationBuilder;
import org.elasticsearch.xpack.spatial.search.aggregations.bucket.geogrid.BoundedGeoHashGridTiler;
import org.elasticsearch.xpack.spatial.search.aggregations.bucket.geogrid.BoundedGeoTileGridTiler;
import org.elasticsearch.xpack.spatial.search.aggregations.bucket.geogrid.GeoGridTiler;
Expand All @@ -66,76 +53,30 @@
import org.elasticsearch.xpack.spatial.search.aggregations.metrics.GeoShapeBoundsAggregator;
import org.elasticsearch.xpack.spatial.search.aggregations.support.GeoShapeValuesSource;
import org.elasticsearch.xpack.spatial.search.aggregations.support.GeoShapeValuesSourceType;
import org.elasticsearch.xpack.spatial.vectortile.RestVectorTileAction;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Supplier;

import static java.util.Collections.singletonList;

public class SpatialPlugin extends GeoPlugin implements ActionPlugin, MapperPlugin, SearchPlugin, IngestPlugin {
private final SpatialUsage usage = new SpatialUsage();
private final SpatialUsage usage = new SpatialUsage();

// to be overriden by tests
protected XPackLicenseState getLicenseState() {
return XPackPlugin.getSharedLicenseState();
}

private static final Boolean VECTOR_TILE_FEATURE_FLAG_REGISTERED;

static {
final String property = System.getProperty("es.vector_tile_feature_flag_registered");
if (Build.CURRENT.isSnapshot() && property != null) {
throw new IllegalArgumentException("es.vector_tile_feature_flag_registered is only supported in non-snapshot builds");
}
if ("true".equals(property)) {
VECTOR_TILE_FEATURE_FLAG_REGISTERED = true;
} else if ("false".equals(property)) {
VECTOR_TILE_FEATURE_FLAG_REGISTERED = false;
} else if (property == null) {
VECTOR_TILE_FEATURE_FLAG_REGISTERED = null;
} else {
throw new IllegalArgumentException(
"expected es.vector_tile_feature_flag_registered to be unset or [true|false] but was [" + property + "]"
);
}
}

public boolean isVectorTileEnabled() {
return Build.CURRENT.isSnapshot() || (VECTOR_TILE_FEATURE_FLAG_REGISTERED != null && VECTOR_TILE_FEATURE_FLAG_REGISTERED);
}

@Override
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
public List<ActionPlugin.ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
return Arrays.asList(
new ActionHandler<>(XPackUsageFeatureAction.SPATIAL, SpatialUsageTransportAction.class),
new ActionHandler<>(XPackInfoFeatureAction.SPATIAL, SpatialInfoTransportAction.class),
new ActionHandler<>(SpatialStatsAction.INSTANCE, SpatialStatsTransportAction.class));
}

@Override
public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings,
IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter,
IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster) {
if (isVectorTileEnabled()) {
return List.of(new RestVectorTileAction());
} else {
return List.of();
}
}

@Override
public List<ExecutorBuilder<?>> getExecutorBuilders(Settings settings) {
FixedExecutorBuilder indexing =
new FixedExecutorBuilder(settings, "vector_tile_generation", 1, -1, "thread_pool.vectortile", false);
return Collections.singletonList(indexing);
new ActionPlugin.ActionHandler<>(XPackUsageFeatureAction.SPATIAL, SpatialUsageTransportAction.class),
new ActionPlugin.ActionHandler<>(XPackInfoFeatureAction.SPATIAL, SpatialInfoTransportAction.class),
new ActionPlugin.ActionHandler<>(SpatialStatsAction.INSTANCE, SpatialStatsTransportAction.class));
}

@Override
Expand Down Expand Up @@ -165,26 +106,14 @@ public List<Consumer<ValuesSourceRegistry.Builder>> getAggregationExtentions() {

@Override
public List<AggregationSpec> getAggregations() {
List<AggregationSpec> aggSpecs = new ArrayList<>();
aggSpecs.add(
return List.of(
new AggregationSpec(
GeoLineAggregationBuilder.NAME,
GeoLineAggregationBuilder::new,
usage.track(SpatialStatsAction.Item.GEOLINE,
checkLicense(GeoLineAggregationBuilder.PARSER, XPackLicenseState.Feature.SPATIAL_GEO_LINE)))
GeoLineAggregationBuilder.NAME,
GeoLineAggregationBuilder::new,
usage.track(SpatialStatsAction.Item.GEOLINE,
checkLicense(GeoLineAggregationBuilder.PARSER, XPackLicenseState.Feature.SPATIAL_GEO_LINE)))
.addResultReader(InternalGeoLine::new)
.setAggregatorRegistrar(GeoLineAggregationBuilder::registerUsage)

);
if (isVectorTileEnabled()) {
aggSpecs.add(new AggregationSpec(VectorTileAggregationBuilder.NAME,
VectorTileAggregationBuilder::new,
VectorTileAggregationBuilder.PARSER)
// usage.track(SpatialStatsAction.Item.GEOLINE,
// checkLicense(VectorTileAggregationBuilder.PARSER, XPackLicenseState.Feature.SPATIAL_GEO_LINE)))
.addResultReader(InternalVectorTile::new).setAggregatorRegistrar(VectorTileAggregationBuilder::registerAggregators));
}
return aggSpecs;
.setAggregatorRegistrar(GeoLineAggregationBuilder::registerUsage));
}

@Override
Expand Down Expand Up @@ -217,7 +146,7 @@ private void registerGeoShapeCentroidAggregator(ValuesSourceRegistry.Builder bui
private void registerGeoShapeGridAggregators(ValuesSourceRegistry.Builder builder) {
builder.register(GeoHashGridAggregationBuilder.REGISTRY_KEY, GeoShapeValuesSourceType.instance(),
(name, factories, valuesSource, precision, geoBoundingBox, requiredSize, shardSize,
aggregationContext, parent, collectsFromSingleBucket, metadata) -> {
aggregationContext, parent, collectsFromSingleBucket, metadata) -> {
if (getLicenseState().checkFeature(XPackLicenseState.Feature.SPATIAL_GEO_GRID)) {
final GeoGridTiler tiler;
if (geoBoundingBox.isUnbounded()) {
Expand All @@ -239,7 +168,7 @@ private void registerGeoShapeGridAggregators(ValuesSourceRegistry.Builder builde

builder.register(GeoTileGridAggregationBuilder.REGISTRY_KEY, GeoShapeValuesSourceType.instance(),
(name, factories, valuesSource, precision, geoBoundingBox, requiredSize, shardSize,
context, parent, collectsFromSingleBucket, metadata) -> {
context, parent, collectsFromSingleBucket, metadata) -> {
if (getLicenseState().checkFeature(XPackLicenseState.Feature.SPATIAL_GEO_GRID)) {
final GeoGridTiler tiler;
if (geoBoundingBox.isUnbounded()) {
Expand Down
Loading