Skip to content

Commit 8d54f59

Browse files
committed
Simplify creation checks
1 parent 2acd563 commit 8d54f59

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,9 @@ public abstract class IndexTemplateRegistry implements ClusterStateListener {
8787
protected final ThreadPool threadPool;
8888
protected final NamedXContentRegistry xContentRegistry;
8989
protected final ClusterService clusterService;
90-
protected final ConcurrentMap<ProjectId, ConcurrentHashMap<String, AtomicBoolean>> templateCreationsInProgress =
91-
new ConcurrentHashMap<>();
92-
protected final ConcurrentMap<ProjectId, ConcurrentHashMap<String, AtomicBoolean>> policyCreationsInProgress =
93-
new ConcurrentHashMap<>();
94-
protected final ConcurrentMap<ProjectId, ConcurrentHashMap<String, AtomicBoolean>> pipelineCreationsInProgress =
95-
new ConcurrentHashMap<>();
90+
protected final ConcurrentMap<String, AtomicBoolean> templateCreationsInProgress = new ConcurrentHashMap<>();
91+
protected final ConcurrentMap<String, AtomicBoolean> policyCreationsInProgress = new ConcurrentHashMap<>();
92+
protected final ConcurrentMap<String, AtomicBoolean> pipelineCreationsInProgress = new ConcurrentHashMap<>();
9693
protected final List<LifecyclePolicy> lifecyclePolicies;
9794
protected final ProjectResolver projectResolver;
9895

@@ -247,6 +244,9 @@ public void clusterChanged(ClusterChangedEvent event) {
247244
return;
248245
}
249246
for (ProjectMetadata project : event.state().metadata().projects().values()) {
247+
if (project.id() != ProjectId.DEFAULT) {
248+
continue;
249+
}
250250
addIngestPipelinesIfMissing(project);
251251
addTemplatesIfMissing(project);
252252
addIndexLifecyclePoliciesIfMissing(project);
@@ -284,8 +284,7 @@ private void addLegacyTemplatesIfMissing(ProjectMetadata project) {
284284
final List<IndexTemplateConfig> indexTemplates = getLegacyTemplateConfigs();
285285
for (IndexTemplateConfig newTemplate : indexTemplates) {
286286
final String templateName = newTemplate.getTemplateName();
287-
final AtomicBoolean creationCheck = templateCreationsInProgress.computeIfAbsent(project.id(), key -> new ConcurrentHashMap<>())
288-
.computeIfAbsent(templateName, key -> new AtomicBoolean(false));
287+
final AtomicBoolean creationCheck = templateCreationsInProgress.computeIfAbsent(templateName, key -> new AtomicBoolean(false));
289288
if (creationCheck.compareAndSet(false, true)) {
290289
IndexTemplateMetadata currentTemplate = project.templates().get(templateName);
291290
if (Objects.isNull(currentTemplate)) {
@@ -325,8 +324,7 @@ private void addComponentTemplatesIfMissing(ProjectMetadata project) {
325324
final Map<String, ComponentTemplate> indexTemplates = getComponentTemplateConfigs();
326325
for (Map.Entry<String, ComponentTemplate> newTemplate : indexTemplates.entrySet()) {
327326
final String templateName = newTemplate.getKey();
328-
final AtomicBoolean creationCheck = templateCreationsInProgress.computeIfAbsent(project.id(), key -> new ConcurrentHashMap<>())
329-
.computeIfAbsent(templateName, key -> new AtomicBoolean(false));
327+
final AtomicBoolean creationCheck = templateCreationsInProgress.computeIfAbsent(templateName, key -> new AtomicBoolean(false));
330328
if (creationCheck.compareAndSet(false, true)) {
331329
ComponentTemplate currentTemplate = project.componentTemplates().get(templateName);
332330
if (templateDependenciesSatisfied(project, newTemplate.getValue()) == false) {
@@ -399,8 +397,7 @@ private void addComposableTemplatesIfMissing(ProjectMetadata project) {
399397
final Map<String, ComposableIndexTemplate> indexTemplates = getComposableTemplateConfigs();
400398
for (Map.Entry<String, ComposableIndexTemplate> newTemplate : indexTemplates.entrySet()) {
401399
final String templateName = newTemplate.getKey();
402-
final AtomicBoolean creationCheck = templateCreationsInProgress.computeIfAbsent(project.id(), key -> new ConcurrentHashMap<>())
403-
.computeIfAbsent(templateName, key -> new AtomicBoolean(false));
400+
final AtomicBoolean creationCheck = templateCreationsInProgress.computeIfAbsent(templateName, key -> new AtomicBoolean(false));
404401
if (creationCheck.compareAndSet(false, true)) {
405402
ComposableIndexTemplate currentTemplate = project.templatesV2().get(templateName);
406403
boolean componentTemplatesAvailable = componentTemplatesInstalled(project, newTemplate.getValue());
@@ -605,8 +602,10 @@ private void addIndexLifecyclePoliciesIfMissing(ProjectMetadata project) {
605602
final IndexLifecycleMetadata metadata = project.custom(IndexLifecycleMetadata.TYPE);
606603
final Map<String, LifecyclePolicy> policies = metadata != null ? metadata.getPolicies() : Map.of();
607604
for (LifecyclePolicy policy : getLifecyclePolicies()) {
608-
final AtomicBoolean creationCheck = policyCreationsInProgress.computeIfAbsent(project.id(), key -> new ConcurrentHashMap<>())
609-
.computeIfAbsent(policy.getName(), key -> new AtomicBoolean(false));
605+
final AtomicBoolean creationCheck = policyCreationsInProgress.computeIfAbsent(
606+
policy.getName(),
607+
key -> new AtomicBoolean(false)
608+
);
610609
if (creationCheck.compareAndSet(false, true)) {
611610
final LifecyclePolicy currentPolicy = policies.get(policy.getName());
612611
if (Objects.isNull(currentPolicy)) {
@@ -679,8 +678,10 @@ protected static Map<String, ComposableIndexTemplate> parseComposableTemplates(I
679678

680679
private void addIngestPipelinesIfMissing(ProjectMetadata project) {
681680
for (IngestPipelineConfig requiredPipeline : getIngestPipelines()) {
682-
final AtomicBoolean creationCheck = pipelineCreationsInProgress.computeIfAbsent(project.id(), key -> new ConcurrentHashMap<>())
683-
.computeIfAbsent(requiredPipeline.getId(), key -> new AtomicBoolean(false));
681+
final AtomicBoolean creationCheck = pipelineCreationsInProgress.computeIfAbsent(
682+
requiredPipeline.getId(),
683+
key -> new AtomicBoolean(false)
684+
);
684685

685686
if (creationCheck.compareAndSet(false, true)) {
686687
List<String> pipelineDependencies = requiredPipeline.getPipelineDependencies();

x-pack/qa/multi-project/xpack-rest-tests-with-multiple-projects/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ dependencies {
1010
testImplementation(testArtifact(project(":x-pack:plugin:security:qa:service-account"), "javaRestTest"))
1111
restXpackTestConfig project(path: ':x-pack:plugin:ilm:qa:rest', configuration: "basicRestSpecs")
1212
restXpackTestConfig project(path: ':x-pack:plugin:downsample:qa:rest', configuration: "basicRestSpecs")
13-
restXpackTestConfig project(path: ':x-pack:plugin:stack', configuration: "basicRestSpecs")
1413
}
1514

1615
// let the yamlRestTests see the classpath of test

0 commit comments

Comments
 (0)