Skip to content

Commit a6df704

Browse files
committed
Move ProjectRoutingInfo to es
1 parent 4e4df61 commit a6df704

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

server/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,4 +491,5 @@
491491
exports org.elasticsearch.inference.telemetry;
492492
exports org.elasticsearch.index.codec.vectors.diskbbq to org.elasticsearch.test.knn;
493493
exports org.elasticsearch.index.codec.vectors.cluster to org.elasticsearch.test.knn;
494+
exports org.elasticsearch.search.crossproject;
494495
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.search.crossproject;
11+
12+
import org.elasticsearch.cluster.metadata.ProjectId;
13+
14+
/**
15+
* Information about a project used for routing in cross-project search.
16+
*/
17+
public record ProjectRoutingInfo(
18+
ProjectId projectId,
19+
String projectType,
20+
String projectAlias,
21+
String organizationId,
22+
ProjectTags projectTags
23+
) {
24+
public ProjectRoutingInfo(ProjectId projectId, ProjectTags projectTags) {
25+
this(projectId, projectTags.projectType(), projectTags.projectAlias(), projectTags.organizationId(), projectTags);
26+
}
27+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.search.crossproject;
11+
12+
import java.util.Map;
13+
14+
/**
15+
* Project tags used for cross-project search routing.
16+
* @param tags the map of tags -- contains both built-in (Elastic-supplied) and custom user-defined tags.
17+
* All built-in tags are prefixed with an underscore (_).
18+
*/
19+
public record ProjectTags(Map<String, String> tags) {
20+
public static final String PROJECT_ID_TAG = "_id";
21+
public static final String PROJECT_ALIAS = "_alias";
22+
public static final String PROJECT_TYPE_TAG = "_type";
23+
public static final String ORGANIZATION_ID_TAG = "_organization";
24+
25+
public String projectId() {
26+
return tags.get(PROJECT_ID_TAG);
27+
}
28+
29+
public String organizationId() {
30+
return tags.get(ORGANIZATION_ID_TAG);
31+
}
32+
33+
public String projectType() {
34+
return tags.get(PROJECT_TYPE_TAG);
35+
}
36+
37+
public String projectAlias() {
38+
return tags.get(PROJECT_ALIAS);
39+
}
40+
41+
/**
42+
* Validate that all required tags are present.
43+
*/
44+
public static void validateTags(String projectId, Map<String, String> tags) {
45+
if (false == tags.containsKey(PROJECT_ID_TAG)) {
46+
throw missingTagException(projectId, PROJECT_ID_TAG);
47+
}
48+
if (false == tags.containsKey(PROJECT_TYPE_TAG)) {
49+
throw missingTagException(projectId, PROJECT_TYPE_TAG);
50+
}
51+
if (false == tags.containsKey(ORGANIZATION_ID_TAG)) {
52+
throw missingTagException(projectId, ORGANIZATION_ID_TAG);
53+
}
54+
if (false == tags.containsKey(PROJECT_ALIAS)) {
55+
throw missingTagException(projectId, PROJECT_ALIAS);
56+
}
57+
}
58+
59+
private static IllegalStateException missingTagException(String projectId, String tagKey) {
60+
return new IllegalStateException("Project configuration for [" + projectId + "] is missing required tag [" + tagKey + "]");
61+
}
62+
}

0 commit comments

Comments
 (0)