Skip to content

Commit 1b5eeb4

Browse files
committed
Merge remote-tracking branch 'upstream/main' into bwc-elastic#125599
2 parents 9596c7f + 015b872 commit 1b5eeb4

File tree

20 files changed

+236
-243
lines changed

20 files changed

+236
-243
lines changed

.buildkite/scripts/dra-workflow.trigger.sh

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,34 @@
22

33
set -euo pipefail
44

5-
echo "steps:"
6-
75
source .buildkite/scripts/branches.sh
86

7+
# We use that filtering to keep different schedule for different branches
8+
if [ -n "${INCLUDED_BRANCHES:-}" ]; then
9+
# If set, only trigger the pipeline for the specified branches
10+
IFS=',' read -r -a BRANCHES <<< "${INCLUDED_BRANCHES}"
11+
elif [ -n "${EXCLUDED_BRANCHES:-}" ]; then
12+
# If set, listed branches will be excluded from the list of branches in branches.json
13+
IFS=',' read -r -a EXCLUDED_BRANCHES <<< "${EXCLUDED_BRANCHES}"
14+
FILTERED_BRANCHES=()
15+
for BRANCH in "${BRANCHES[@]}"; do
16+
EXCLUDE=false
17+
for EXCLUDED_BRANCH in "${EXCLUDED_BRANCHES[@]}"; do
18+
if [ "$BRANCH" == "$EXCLUDED_BRANCH" ]; then
19+
EXCLUDE=true
20+
break
21+
fi
22+
done
23+
if [ "$EXCLUDE" = false ]; then
24+
FILTERED_BRANCHES+=("$BRANCH")
25+
fi
26+
done
27+
BRANCHES=("${FILTERED_BRANCHES[@]}")
28+
fi
29+
30+
31+
echo "steps:"
32+
933
for BRANCH in "${BRANCHES[@]}"; do
1034
INTAKE_PIPELINE_SLUG="elasticsearch-intake"
1135
BUILD_JSON=$(curl -sH "Authorization: Bearer ${BUILDKITE_API_TOKEN}" "https://api.buildkite.com/v2/organizations/elastic/pipelines/${INTAKE_PIPELINE_SLUG}/builds?branch=${BRANCH}&state=passed&per_page=1" | jq '.[0] | {commit: .commit, url: .web_url}')

plugins/examples/build.gradle

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,16 @@ subprojects {
2222

2323
repositories {
2424
// Only necessary when building plugins against SNAPSHOT versions of Elasticsearch
25-
maven {
26-
url = 'https://snapshots.elastic.co/maven/'
27-
mavenContent {
28-
if (gradle.includedBuilds) {
29-
// When building in a composite, restrict this to only resolve the Java REST client
30-
includeModule 'co.elastic.clients', 'elasticsearch-java'
31-
}
32-
}
33-
}
3425
if (gradle.includedBuilds.isEmpty()) {
3526
maven {
3627
url = "https://artifacts-snapshot.elastic.co/elasticsearch/${elasticsearchVersion}/maven"
3728
mavenContent {
3829
includeModule 'org.elasticsearch', 'elasticsearch'
3930
}
4031
}
32+
maven {
33+
url = 'https://snapshots.elastic.co/maven/'
34+
}
4135
}
4236

4337
// Same for Lucene, add the snapshot repo based on the currently used Lucene version

plugins/examples/security-authorization-engine/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dependencies {
1616
testImplementation "org.elasticsearch.plugin:x-pack-core:${elasticsearchVersion}"
1717
javaRestTestImplementation "org.elasticsearch.plugin:x-pack-core:${elasticsearchVersion}"
1818
javaRestTestImplementation "org.apache.logging.log4j:log4j-core:${log4jVersion}"
19-
javaRestTestImplementation("co.elastic.clients:elasticsearch-java:${elasticsearchVersion}")
19+
javaRestTestImplementation "co.elastic.clients:elasticsearch-java:[9.0,10.0)"
2020
javaRestTestImplementation "org.elasticsearch.client:elasticsearch-rest-client:${elasticsearchVersion}"
2121
javaRestTestImplementation 'com.fasterxml.jackson.core:jackson-databind:2.12.3'
2222
javaRestTestImplementation "org.elasticsearch.test:framework:${elasticsearchVersion}"

server/src/main/java/org/elasticsearch/index/fieldvisitor/FieldsVisitor.java

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
import java.util.Set;
3030
import java.util.function.Function;
3131

32-
import static java.util.Collections.emptyMap;
33-
3432
/**
3533
* Base {@link StoredFieldVisitor} that retrieves all non-redundant metadata.
3634
*/
@@ -40,9 +38,9 @@ public class FieldsVisitor extends FieldNamesProvidingStoredFieldsVisitor {
4038
private final boolean loadSource;
4139
final String sourceFieldName;
4240
private final Set<String> requiredFields;
43-
protected BytesReference source;
44-
protected String id;
45-
protected Map<String, List<Object>> fieldsValues;
41+
private BytesReference source;
42+
private String id;
43+
private final Map<String, List<Object>> fieldsValues = new HashMap<>();
4644

4745
public FieldsVisitor(boolean loadSource) {
4846
this(loadSource, SourceFieldMapper.NAME);
@@ -58,24 +56,29 @@ public FieldsVisitor(boolean loadSource, String sourceFieldName) {
5856

5957
@Override
6058
public Status needsField(FieldInfo fieldInfo) {
61-
if (requiredFields.remove(fieldInfo.name)) {
59+
final String name = fieldInfo.name;
60+
var requiredFields = this.requiredFields;
61+
if (requiredFields.remove(name)) {
6262
return Status.YES;
6363
}
6464
// Always load _ignored to be explicit about ignored fields
6565
// This works because _ignored is added as the first metadata mapper,
6666
// so its stored fields always appear first in the list.
6767
// Note that _ignored is also multi-valued, which is why it can't be removed from the set like other fields
68-
if (IgnoredFieldMapper.NAME.equals(fieldInfo.name)) {
68+
if (IgnoredFieldMapper.NAME.equals(name)) {
6969
return Status.YES;
7070
}
71+
// All these fields are single-valued so we can stop when the set is empty
72+
if (requiredFields.isEmpty()) {
73+
return Status.STOP;
74+
}
7175
// support _uid for loading older indices
72-
if ("_uid".equals(fieldInfo.name)) {
76+
if ("_uid".equals(name)) {
7377
if (requiredFields.remove(IdFieldMapper.NAME) || requiredFields.remove(LegacyTypeFieldMapper.NAME)) {
7478
return Status.YES;
7579
}
7680
}
77-
// All these fields are single-valued so we can stop when the set is empty
78-
return requiredFields.isEmpty() ? Status.STOP : Status.NO;
81+
return Status.NO;
7982
}
8083

8184
@Override
@@ -98,33 +101,31 @@ public final void postProcess(Function<String, MappedFieldType> fieldTypeLookup)
98101

99102
@Override
100103
public void binaryField(FieldInfo fieldInfo, byte[] value) {
101-
binaryField(fieldInfo, new BytesRef(value));
102-
}
103-
104-
private void binaryField(FieldInfo fieldInfo, BytesRef value) {
105-
if (sourceFieldName.equals(fieldInfo.name)) {
104+
final String name = fieldInfo.name;
105+
if (sourceFieldName.equals(name)) {
106106
source = new BytesArray(value);
107-
} else if (IdFieldMapper.NAME.equals(fieldInfo.name)) {
108-
id = Uid.decodeId(value.bytes, value.offset, value.length);
107+
} else if (IdFieldMapper.NAME.equals(name)) {
108+
id = Uid.decodeId(value, 0, value.length);
109109
} else {
110-
addValue(fieldInfo.name, value);
110+
addValue(name, new BytesRef(value));
111111
}
112112
}
113113

114114
@Override
115115
public void stringField(FieldInfo fieldInfo, String value) {
116-
assert sourceFieldName.equals(fieldInfo.name) == false : "source field must go through binaryField";
117-
if ("_uid".equals(fieldInfo.name)) {
116+
final String name = fieldInfo.name;
117+
assert sourceFieldName.equals(name) == false : "source field must go through binaryField";
118+
if ("_uid".equals(name)) {
118119
// 5.x-only
119120
int delimiterIndex = value.indexOf('#'); // type is not allowed to have # in it..., ids can
120121
String type = value.substring(0, delimiterIndex);
121122
id = value.substring(delimiterIndex + 1);
122123
addValue(LegacyTypeFieldMapper.NAME, type);
123-
} else if (IdFieldMapper.NAME.equals(fieldInfo.name)) {
124+
} else if (IdFieldMapper.NAME.equals(name)) {
124125
// only applies to 5.x indices that have single_type = true
125126
id = value;
126127
} else {
127-
addValue(fieldInfo.name, value);
128+
addValue(name, value);
128129
}
129130
}
130131

@@ -157,25 +158,20 @@ public String id() {
157158
}
158159

159160
public String routing() {
160-
if (fieldsValues == null) {
161-
return null;
162-
}
163161
List<Object> values = fieldsValues.get(RoutingFieldMapper.NAME);
164162
if (values == null || values.isEmpty()) {
165163
return null;
166164
}
167165
assert values.size() == 1;
168-
return values.get(0).toString();
166+
return values.getFirst().toString();
169167
}
170168

171169
public Map<String, List<Object>> fields() {
172-
return fieldsValues != null ? fieldsValues : emptyMap();
170+
return fieldsValues;
173171
}
174172

175173
public void reset() {
176-
if (fieldsValues != null) {
177-
fieldsValues.clear();
178-
}
174+
fieldsValues.clear();
179175
source = null;
180176
id = null;
181177

@@ -186,11 +182,6 @@ public void reset() {
186182
}
187183

188184
void addValue(String name, Object value) {
189-
if (fieldsValues == null) {
190-
fieldsValues = new HashMap<>();
191-
}
192-
193-
List<Object> values = fieldsValues.computeIfAbsent(name, k -> new ArrayList<>(2));
194-
values.add(value);
185+
fieldsValues.computeIfAbsent(name, k -> new ArrayList<>(2)).add(value);
195186
}
196187
}
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import org.elasticsearch.gradle.testclusters.StandaloneRestIntegTestTask
2-
31
apply plugin: 'elasticsearch.internal-es-plugin'
42
apply plugin: 'elasticsearch.test-with-dependencies'
53
apply plugin: 'elasticsearch.internal-java-rest-test'
@@ -12,12 +10,10 @@ esplugin {
1210
dependencies {
1311
testImplementation project(path: ':test:test-clusters')
1412
clusterModules project(':test:external-modules:test-multi-project')
15-
}
16-
17-
tasks.withType(StandaloneRestIntegTestTask).configureEach {
18-
usesDefaultDistribution("to be triaged")
13+
clusterModules project(':modules:analysis-common')
1914
}
2015

2116
tasks.named("javaRestTest").configure {
2217
enabled = buildParams.snapshotBuild
18+
systemProperty "tests.multi_project.enabled", true
2319
}

test/external-modules/multi-project/src/javaRestTest/java/org/elasticsearch/action/admin/indices/IndexMultiProjectCRUDIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class IndexMultiProjectCRUDIT extends MultiProjectRestTestCase {
4646
private static ElasticsearchCluster createCluster() {
4747
LocalClusterSpecBuilder<ElasticsearchCluster> clusterBuilder = ElasticsearchCluster.local()
4848
.nodes(NODE_NUM)
49-
.distribution(DistributionType.INTEG_TEST) // TODO multi-project: make this test suite work under the default distrib
49+
.distribution(DistributionType.INTEG_TEST)
5050
.module("test-multi-project")
5151
.setting("test.multi_project.enabled", "true")
5252
.setting("xpack.security.enabled", "false") // TODO multi-project: make this test suite work with Security enabled

test/external-modules/multi-project/src/javaRestTest/java/org/elasticsearch/action/index/IndexDocumentMultiProjectIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class IndexDocumentMultiProjectIT extends MultiProjectRestTestCase {
4242
private static ElasticsearchCluster createCluster() {
4343
LocalClusterSpecBuilder<ElasticsearchCluster> clusterBuilder = ElasticsearchCluster.local()
4444
.nodes(NODE_NUM)
45-
.distribution(DistributionType.INTEG_TEST) // TODO multi-project: make this test suite work under the default distrib
45+
.distribution(DistributionType.INTEG_TEST)
4646
.module("test-multi-project")
4747
.setting("test.multi_project.enabled", "true")
4848
.setting("xpack.security.enabled", "false") // TODO multi-project: make this test suite work with Security enabled

test/external-modules/multi-project/src/javaRestTest/java/org/elasticsearch/multiproject/MultiProjectClusterStateActionIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class MultiProjectClusterStateActionIT extends MultiProjectRestTestCase {
2525

2626
@ClassRule
2727
public static ElasticsearchCluster CLUSTER = ElasticsearchCluster.local()
28-
.distribution(DistributionType.DEFAULT)
28+
.distribution(DistributionType.INTEG_TEST)
2929
.setting("test.multi_project.enabled", "true")
3030
.setting("xpack.security.http.ssl.enabled", "false")
3131
.setting("xpack.security.enabled", "false")

test/external-modules/multi-project/src/javaRestTest/java/org/elasticsearch/multiproject/MultiProjectRestTestCase.java

Lines changed: 12 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,77 +11,32 @@
1111

1212
import org.elasticsearch.client.Request;
1313
import org.elasticsearch.client.RequestOptions;
14-
import org.elasticsearch.client.Response;
15-
import org.elasticsearch.client.ResponseException;
16-
import org.elasticsearch.cluster.metadata.Metadata;
1714
import org.elasticsearch.tasks.Task;
1815
import org.elasticsearch.test.rest.ESRestTestCase;
19-
import org.elasticsearch.xcontent.ObjectPath;
2016
import org.junit.After;
2117

2218
import java.io.IOException;
23-
import java.util.List;
24-
import java.util.Map;
25-
import java.util.Set;
26-
import java.util.stream.Collectors;
2719

2820
public abstract class MultiProjectRestTestCase extends ESRestTestCase {
29-
protected static Request setRequestProjectId(Request request, String projectId) {
30-
RequestOptions.Builder options = request.getOptions().toBuilder();
31-
options.removeHeader(Task.X_ELASTIC_PROJECT_ID_HTTP_HEADER);
32-
options.addHeader(Task.X_ELASTIC_PROJECT_ID_HTTP_HEADER, projectId);
33-
request.setOptions(options);
34-
return request;
35-
}
36-
37-
protected static void clearRequestProjectId(Request request) {
38-
RequestOptions options = request.getOptions();
39-
if (options.containsHeader(Task.X_ELASTIC_PROJECT_ID_HTTP_HEADER)) {
40-
request.setOptions(options.toBuilder().removeHeader(Task.X_ELASTIC_PROJECT_ID_HTTP_HEADER).build());
41-
}
42-
}
43-
44-
protected void createProject(String projectId) throws IOException {
45-
Request request = new Request("PUT", "/_project/" + projectId);
46-
try {
47-
Response response = adminClient().performRequest(request);
48-
assertOK(response);
49-
logger.info("Created project {} : {}", projectId, response.getStatusLine());
50-
} catch (ResponseException e) {
51-
logger.error("Failed to create project: {}", projectId);
52-
throw e;
53-
}
54-
}
55-
56-
protected void deleteProject(String projectId) throws IOException {
57-
final Request request = new Request("DELETE", "/_project/" + projectId);
58-
try {
59-
final Response response = adminClient().performRequest(request);
60-
logger.info("Deleted project {} : {}", projectId, response.getStatusLine());
61-
} catch (ResponseException e) {
62-
logger.error("Failed to delete project: {}", projectId);
63-
throw e;
64-
}
65-
}
6621

67-
protected Set<String> listProjects() throws IOException {
68-
final Request request = new Request("GET", "/_cluster/state/metadata?multi_project");
69-
final Response response = adminClient().performRequest(request);
70-
final List<Map<String, ?>> projects = ObjectPath.eval("metadata.projects", entityAsMap(response));
71-
return projects.stream().map(m -> String.valueOf(m.get("id"))).collect(Collectors.toSet());
22+
@Override
23+
protected boolean shouldConfigureProjects() {
24+
return false;
7225
}
7326

7427
@After
7528
public void removeNonDefaultProjects() throws IOException {
7629
if (preserveClusterUponCompletion() == false) {
77-
final Set<String> projects = listProjects();
78-
logger.info("Removing non-default projects from {}", projects);
79-
for (String projectId : projects) {
80-
if (projectId.equals(Metadata.DEFAULT_PROJECT_ID.id()) == false) {
81-
deleteProject(projectId);
82-
}
83-
}
30+
cleanUpProjects();
8431
}
8532
}
8633

34+
protected static Request setRequestProjectId(Request request, String projectId) {
35+
RequestOptions.Builder options = request.getOptions().toBuilder();
36+
options.removeHeader(Task.X_ELASTIC_PROJECT_ID_HTTP_HEADER);
37+
options.addHeader(Task.X_ELASTIC_PROJECT_ID_HTTP_HEADER, projectId);
38+
request.setOptions(options);
39+
return request;
40+
}
41+
8742
}

test/external-modules/multi-project/src/javaRestTest/java/org/elasticsearch/multiproject/MultiProjectRestartIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class MultiProjectRestartIT extends MultiProjectRestTestCase {
2323

2424
@ClassRule
2525
public static ElasticsearchCluster CLUSTER = ElasticsearchCluster.local()
26-
.distribution(DistributionType.DEFAULT)
26+
.distribution(DistributionType.INTEG_TEST)
2727
.setting("test.multi_project.enabled", "true")
2828
.setting("xpack.security.http.ssl.enabled", "false")
2929
.setting("xpack.security.enabled", "false")

0 commit comments

Comments
 (0)