Skip to content

Commit

Permalink
Update connector templates to use a historical feature (#101531)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecoop committed Nov 13, 2023
1 parent 91df0ce commit 25bf934
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 6 deletions.
2 changes: 2 additions & 0 deletions x-pack/plugin/ent-search/src/main/java/module-info.java
Expand Up @@ -33,4 +33,6 @@
exports org.elasticsearch.xpack.application.search.action;
exports org.elasticsearch.xpack.application.rules;
exports org.elasticsearch.xpack.application.rules.action;

provides org.elasticsearch.features.FeatureSpecification with org.elasticsearch.xpack.application.EnterpriseSearchFeatures;
}
Expand Up @@ -201,6 +201,7 @@ public Collection<?> createComponents(PluginServices services) {
// Connector components
final ConnectorTemplateRegistry connectorTemplateRegistry = new ConnectorTemplateRegistry(
services.clusterService(),
services.featureService(),
services.threadPool(),
services.client(),
services.xContentRegistry()
Expand Down
@@ -0,0 +1,22 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.application;

import org.elasticsearch.Version;
import org.elasticsearch.features.FeatureSpecification;
import org.elasticsearch.features.NodeFeature;
import org.elasticsearch.xpack.application.connector.ConnectorTemplateRegistry;

import java.util.Map;

public class EnterpriseSearchFeatures implements FeatureSpecification {
@Override
public Map<NodeFeature, Version> getHistoricalFeatures() {
return Map.of(ConnectorTemplateRegistry.CONNECTOR_TEMPLATES_FEATURE, Version.V_8_10_0);
}
}
Expand Up @@ -7,13 +7,14 @@

package org.elasticsearch.xpack.application.connector;

import org.elasticsearch.Version;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.cluster.ClusterChangedEvent;
import org.elasticsearch.cluster.metadata.ComponentTemplate;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.features.FeatureService;
import org.elasticsearch.features.NodeFeature;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContentParserConfiguration;
Expand All @@ -32,7 +33,7 @@

public class ConnectorTemplateRegistry extends IndexTemplateRegistry {

static final Version MIN_NODE_VERSION = Version.V_8_10_0;
public static final NodeFeature CONNECTOR_TEMPLATES_FEATURE = new NodeFeature("elastic-connectors.templates");

// This number must be incremented when we make changes to built-in templates.
static final int REGISTRY_VERSION = 1;
Expand Down Expand Up @@ -145,13 +146,17 @@ protected List<IngestPipelineConfig> getIngestPipelines() {
)
);

private final FeatureService featureService;

public ConnectorTemplateRegistry(
ClusterService clusterService,
FeatureService featureService,
ThreadPool threadPool,
Client client,
NamedXContentRegistry xContentRegistry
) {
super(Settings.EMPTY, clusterService, threadPool, client, xContentRegistry);
this.featureService = featureService;
}

@Override
Expand All @@ -177,8 +182,6 @@ protected boolean requiresMasterNode() {

@Override
protected boolean isClusterReady(ClusterChangedEvent event) {
// Ensure templates are installed only once all nodes are updated to 8.10.0.
Version minNodeVersion = event.state().nodes().getMinNodeVersion();
return minNodeVersion.onOrAfter(MIN_NODE_VERSION);
return featureService.clusterHasFeature(event.state(), CONNECTOR_TEMPLATES_FEATURE);
}
}
@@ -0,0 +1,8 @@
#
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. Licensed under the Elastic License
# 2.0; you may not use this file except in compliance with the Elastic License
# 2.0.
#

org.elasticsearch.xpack.application.EnterpriseSearchFeatures
Expand Up @@ -31,6 +31,7 @@
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.Strings;
import org.elasticsearch.features.FeatureService;
import org.elasticsearch.ingest.IngestMetadata;
import org.elasticsearch.ingest.PipelineConfiguration;
import org.elasticsearch.test.ClusterServiceUtils;
Expand All @@ -40,6 +41,7 @@
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContentType;
import org.elasticsearch.xpack.application.EnterpriseSearchFeatures;
import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata;
import org.elasticsearch.xpack.core.ilm.LifecyclePolicy;
import org.elasticsearch.xpack.core.ilm.LifecyclePolicyMetadata;
Expand Down Expand Up @@ -78,7 +80,8 @@ public void createRegistryAndClient() {
threadPool = new TestThreadPool(this.getClass().getName());
client = new VerifyingClient(threadPool);
ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool);
registry = new ConnectorTemplateRegistry(clusterService, threadPool, client, NamedXContentRegistry.EMPTY);
FeatureService featureService = new FeatureService(List.of(new EnterpriseSearchFeatures()));
registry = new ConnectorTemplateRegistry(clusterService, featureService, threadPool, client, NamedXContentRegistry.EMPTY);
}

@After
Expand Down

0 comments on commit 25bf934

Please sign in to comment.