Skip to content

Commit b5fccd1

Browse files
authored
Introduce Spatial Plugin (#44389)
This commit introduces a skeleton Spatial plugin that will be filled-in with some new licensed features coming to Geo/Spatial land!
1 parent 4fd8e34 commit b5fccd1

File tree

13 files changed

+339
-3
lines changed

13 files changed

+339
-3
lines changed

docs/reference/rest-api/info.asciidoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ Example response:
107107
"available" : true,
108108
"enabled" : false
109109
},
110+
"spatial" : {
111+
"available" : true,
112+
"enabled" : true
113+
},
110114
"sql" : {
111115
"available" : true,
112116
"enabled" : true

x-pack/plugin/core/src/main/java/org/elasticsearch/license/XPackLicenseState.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,22 @@ public synchronized boolean isOdbcAllowed() {
728728
return licensed && localStatus.active;
729729
}
730730

731+
/**
732+
* Determine if Spatial features should be enabled.
733+
* <p>
734+
* Spatial features are available in for all license types except
735+
* {@link OperationMode#MISSING}
736+
*
737+
* @return {@code true} as long as the license is valid. Otherwise
738+
* {@code false}.
739+
*/
740+
public boolean isSpatialAllowed() {
741+
// status is volatile
742+
Status localStatus = status;
743+
// Should work on all active licenses
744+
return localStatus.active;
745+
}
746+
731747
public synchronized boolean isTrialLicense() {
732748
return status.mode == OperationMode.TRIAL;
733749
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClientPlugin.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@
192192
import org.elasticsearch.xpack.core.security.authc.support.mapper.expressiondsl.RoleMapperExpression;
193193
import org.elasticsearch.xpack.core.security.authz.privilege.ConditionalClusterPrivilege;
194194
import org.elasticsearch.xpack.core.security.authz.privilege.ConditionalClusterPrivileges;
195+
import org.elasticsearch.xpack.core.spatial.SpatialFeatureSetUsage;
195196
import org.elasticsearch.xpack.core.sql.SqlFeatureSetUsage;
196197
import org.elasticsearch.xpack.core.ssl.action.GetCertificateInfoAction;
197198
import org.elasticsearch.xpack.core.upgrade.actions.IndexUpgradeAction;
@@ -507,7 +508,9 @@ public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
507508
// Voting Only Node
508509
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.VOTING_ONLY, VotingOnlyNodeFeatureSetUsage::new),
509510
// Frozen indices
510-
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.FROZEN_INDICES, FrozenIndicesFeatureSetUsage::new)
511+
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.FROZEN_INDICES, FrozenIndicesFeatureSetUsage::new),
512+
// Spatial
513+
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.SPATIAL, SpatialFeatureSetUsage::new)
511514
);
512515
}
513516

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackField.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public final class XPackField {
4545
public static final String VOTING_ONLY = "voting_only";
4646
/** Name constant for the frozen index feature. */
4747
public static final String FROZEN_INDICES = "frozen_indices";
48+
/** Name constant for spatial features. */
49+
public static final String SPATIAL = "spatial";
4850

4951
private XPackField() {}
5052

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackInfoFeatureAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ public class XPackInfoFeatureAction extends ActionType<XPackInfoFeatureResponse>
3737
public static final XPackInfoFeatureAction VECTORS = new XPackInfoFeatureAction(XPackField.VECTORS);
3838
public static final XPackInfoFeatureAction VOTING_ONLY = new XPackInfoFeatureAction(XPackField.VOTING_ONLY);
3939
public static final XPackInfoFeatureAction FROZEN_INDICES = new XPackInfoFeatureAction(XPackField.FROZEN_INDICES);
40+
public static final XPackInfoFeatureAction SPATIAL = new XPackInfoFeatureAction(XPackField.SPATIAL);
4041

4142
public static final List<XPackInfoFeatureAction> ALL = Arrays.asList(
4243
SECURITY, MONITORING, WATCHER, GRAPH, MACHINE_LEARNING, LOGSTASH, SQL, ROLLUP, INDEX_LIFECYCLE, CCR, DATA_FRAME, FLATTENED,
43-
VECTORS, VOTING_ONLY, FROZEN_INDICES
44+
VECTORS, VOTING_ONLY, FROZEN_INDICES, SPATIAL
4445
);
4546

4647
private XPackInfoFeatureAction(String name) {

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackUsageFeatureAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ public class XPackUsageFeatureAction extends ActionType<XPackUsageFeatureRespons
3737
public static final XPackUsageFeatureAction VECTORS = new XPackUsageFeatureAction(XPackField.VECTORS);
3838
public static final XPackUsageFeatureAction VOTING_ONLY = new XPackUsageFeatureAction(XPackField.VOTING_ONLY);
3939
public static final XPackUsageFeatureAction FROZEN_INDICES = new XPackUsageFeatureAction(XPackField.FROZEN_INDICES);
40+
public static final XPackUsageFeatureAction SPATIAL = new XPackUsageFeatureAction(XPackField.SPATIAL);
4041

4142
public static final List<XPackUsageFeatureAction> ALL = Arrays.asList(
4243
SECURITY, MONITORING, WATCHER, GRAPH, MACHINE_LEARNING, LOGSTASH, SQL, ROLLUP, INDEX_LIFECYCLE, CCR, DATA_FRAME, FLATTENED,
43-
VECTORS, VOTING_ONLY, FROZEN_INDICES
44+
VECTORS, VOTING_ONLY, FROZEN_INDICES, SPATIAL
4445
);
4546

4647
private XPackUsageFeatureAction(String name) {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
package org.elasticsearch.xpack.core.spatial;
8+
9+
import org.elasticsearch.common.io.stream.StreamInput;
10+
import org.elasticsearch.common.io.stream.StreamOutput;
11+
import org.elasticsearch.xpack.core.XPackFeatureSet;
12+
import org.elasticsearch.xpack.core.XPackField;
13+
14+
import java.io.IOException;
15+
import java.util.Objects;
16+
17+
public class SpatialFeatureSetUsage extends XPackFeatureSet.Usage {
18+
19+
public SpatialFeatureSetUsage(boolean available, boolean enabled) {
20+
super(XPackField.SPATIAL, available, enabled);
21+
}
22+
23+
public SpatialFeatureSetUsage(StreamInput input) throws IOException {
24+
super(input);
25+
}
26+
27+
@Override
28+
public void writeTo(StreamOutput out) throws IOException {
29+
super.writeTo(out);
30+
}
31+
32+
@Override
33+
public int hashCode() {
34+
return Objects.hash(available, enabled);
35+
}
36+
37+
@Override
38+
public boolean equals(Object obj) {
39+
if (obj == null) {
40+
return false;
41+
}
42+
if (getClass() != obj.getClass()) {
43+
return false;
44+
}
45+
SpatialFeatureSetUsage other = (SpatialFeatureSetUsage) obj;
46+
return Objects.equals(available, other.available) &&
47+
Objects.equals(enabled, other.enabled);
48+
}
49+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
package org.elasticsearch.xpack.core.spatial;
7+
8+
import org.elasticsearch.common.io.stream.Writeable;
9+
import org.elasticsearch.test.AbstractWireSerializingTestCase;
10+
11+
import java.io.IOException;
12+
13+
public class SpatialFeatureSetUsageTests extends AbstractWireSerializingTestCase<SpatialFeatureSetUsage> {
14+
15+
@Override
16+
protected SpatialFeatureSetUsage createTestInstance() {
17+
boolean available = randomBoolean();
18+
boolean enabled = randomBoolean();
19+
return new SpatialFeatureSetUsage(available, enabled);
20+
}
21+
22+
@Override
23+
protected SpatialFeatureSetUsage mutateInstance(SpatialFeatureSetUsage instance) throws IOException {
24+
boolean available = instance.available();
25+
boolean enabled = instance.enabled();
26+
switch (between(0, 1)) {
27+
case 0:
28+
available = available == false;
29+
break;
30+
case 1:
31+
enabled = enabled == false;
32+
break;
33+
default:
34+
throw new AssertionError("Illegal randomisation branch");
35+
}
36+
return new SpatialFeatureSetUsage(available, enabled);
37+
}
38+
39+
@Override
40+
protected Writeable.Reader<SpatialFeatureSetUsage> instanceReader() {
41+
return SpatialFeatureSetUsage::new;
42+
}
43+
44+
}

x-pack/plugin/spatial/build.gradle

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
evaluationDependsOn(xpackModule('core'))
2+
3+
apply plugin: 'elasticsearch.esplugin'
4+
5+
esplugin {
6+
name 'spatial'
7+
description 'A plugin for Basic Spatial features'
8+
classname 'org.elasticsearch.xpack.spatial.SpatialPlugin'
9+
extendedPlugins = ['x-pack-core']
10+
}
11+
12+
dependencies {
13+
compileOnly project(path: xpackModule('core'), configuration: 'default')
14+
testCompile project(path: xpackModule('core'), configuration: 'testArtifacts')
15+
if (isEclipse) {
16+
testCompile project(path: xpackModule('core-tests'), configuration: 'testArtifacts')
17+
}
18+
}
19+
20+
// xpack modules are installed in real clusters as the meta plugin, so
21+
// installing them as individual plugins for integ tests doesn't make sense,
22+
// so we disable integ tests
23+
integTest.enabled = false
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
package org.elasticsearch.xpack.spatial;
7+
8+
import org.elasticsearch.action.support.ActionFilters;
9+
import org.elasticsearch.common.inject.Inject;
10+
import org.elasticsearch.common.settings.Settings;
11+
import org.elasticsearch.license.XPackLicenseState;
12+
import org.elasticsearch.transport.TransportService;
13+
import org.elasticsearch.xpack.core.XPackField;
14+
import org.elasticsearch.xpack.core.action.XPackInfoFeatureAction;
15+
import org.elasticsearch.xpack.core.action.XPackInfoFeatureTransportAction;
16+
17+
public class SpatialInfoTransportAction extends XPackInfoFeatureTransportAction {
18+
19+
private final XPackLicenseState licenseState;
20+
21+
@Inject
22+
public SpatialInfoTransportAction(TransportService transportService, ActionFilters actionFilters,
23+
Settings settings, XPackLicenseState licenseState) {
24+
super(XPackInfoFeatureAction.SPATIAL.name(), transportService, actionFilters);
25+
this.licenseState = licenseState;
26+
}
27+
28+
@Override
29+
public String name() {
30+
return XPackField.SPATIAL;
31+
}
32+
33+
@Override
34+
public boolean available() {
35+
return licenseState.isSpatialAllowed();
36+
}
37+
38+
@Override
39+
public boolean enabled() {
40+
return true;
41+
}
42+
43+
}

0 commit comments

Comments
 (0)