Skip to content

Commit

Permalink
Convert graph license object to LicensedFeature (elastic#78656)
Browse files Browse the repository at this point in the history
This commit moves the graph license checks to use the new
LicensedFeature class.
  • Loading branch information
rjernst authored Oct 5, 2021
1 parent b5b73ed commit 06d6fb9
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ public enum Feature {

CCR(OperationMode.PLATINUM, true),

GRAPH(OperationMode.PLATINUM, true),

MACHINE_LEARNING(OperationMode.PLATINUM, true),

OPERATOR_PRIVILEGES(OperationMode.ENTERPRISE, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.elasticsearch.common.settings.IndexScopedSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.license.License;
import org.elasticsearch.license.LicensedFeature;
import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.RestController;
Expand All @@ -34,6 +36,8 @@

public class Graph extends Plugin implements ActionPlugin {

public static final LicensedFeature.Momentary GRAPH_FEATURE = LicensedFeature.momentary(null, "graph", License.OperationMode.PLATINUM);

protected final boolean enabled;

public Graph(Settings settings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public String name() {

@Override
public boolean available() {
return licenseState != null && licenseState.isAllowed(XPackLicenseState.Feature.GRAPH);
return licenseState != null && Graph.GRAPH_FEATURE.checkWithoutTracking(licenseState);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.license.XPackLicenseState.Feature;
import org.elasticsearch.protocol.xpack.XPackUsageRequest;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.threadpool.ThreadPool;
Expand Down Expand Up @@ -44,7 +43,7 @@ public GraphUsageTransportAction(TransportService transportService, ClusterServi
protected void masterOperation(Task task, XPackUsageRequest request, ClusterState state,
ActionListener<XPackUsageFeatureResponse> listener) {
GraphFeatureSetUsage usage =
new GraphFeatureSetUsage(licenseState.isAllowed(Feature.GRAPH), XPackSettings.GRAPH_ENABLED.get(settings));
new GraphFeatureSetUsage(Graph.GRAPH_FEATURE.checkWithoutTracking(licenseState), XPackSettings.GRAPH_ENABLED.get(settings));
listener.onResponse(new XPackUsageFeatureResponse(usage));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.xpack.core.XPackField;
import org.elasticsearch.xpack.core.graph.action.GraphExploreAction;
import org.elasticsearch.xpack.graph.Graph;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -93,7 +94,7 @@ public TransportGraphExploreAction(ThreadPool threadPool, NodeClient client, Tra

@Override
protected void doExecute(Task task, GraphExploreRequest request, ActionListener<GraphExploreResponse> listener) {
if (licenseState.checkFeature(XPackLicenseState.Feature.GRAPH)) {
if (Graph.GRAPH_FEATURE.check(licenseState)) {
new AsyncGraphAction(request, listener).start();
} else {
listener.onFailure(LicenseUtils.newComplianceException(XPackField.GRAPH));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.license.MockLicenseState;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.xpack.core.XPackFeatureSet;
Expand All @@ -24,18 +24,18 @@

public class GraphInfoTransportActionTests extends ESTestCase {

private XPackLicenseState licenseState;
private MockLicenseState licenseState;

@Before
public void init() throws Exception {
licenseState = mock(XPackLicenseState.class);
licenseState = mock(MockLicenseState.class);
}

public void testAvailable() throws Exception {
GraphInfoTransportAction featureSet = new GraphInfoTransportAction(
mock(TransportService.class), mock(ActionFilters.class), Settings.EMPTY, licenseState);
boolean available = randomBoolean();
when(licenseState.isAllowed(XPackLicenseState.Feature.GRAPH)).thenReturn(available);
when(licenseState.isAllowed(Graph.GRAPH_FEATURE)).thenReturn(available);
assertThat(featureSet.available(), is(available));

var usageAction = new GraphUsageTransportAction(mock(TransportService.class), null, null,
Expand Down

0 comments on commit 06d6fb9

Please sign in to comment.