Merge branch 'stable-2.15'
* stable-2.15: Elasticsearch: Adapt version discovery for version 6 AbstractIndexTests#assertQuery: Rename to assertChangeQuery ProjectConfig#saveLabelSections: Save "branch" values Update git submodules Make ElasticIndexIT tests fail if test container fails to start gr-change-metadata: Change "Add assignee" to "Set assignee" Add missing build dependencies for ElasticReindexIT Upgrade testcontainers to version 1.8.0 Make ElasticReindexIT tests fail if test container fails to start Change-Id: I65d98a736953f4affe188b1674ec9f76f7cd8ab2
This commit is contained in:
commit
0bfe395b3b
|
@ -924,8 +924,8 @@ maven_jar(
|
|||
|
||||
maven_jar(
|
||||
name = "testcontainers",
|
||||
artifact = "org.testcontainers:testcontainers:1.7.2",
|
||||
sha1 = "fec8b360b6b613f6c9d3b8e7a9fa32d1a2bcb978",
|
||||
artifact = "org.testcontainers:testcontainers:1.8.0",
|
||||
sha1 = "bc413912f7044f9f12aa0782853aef0a067ee52a",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
|
|
|
@ -16,18 +16,21 @@ package com.google.gerrit.elasticsearch;
|
|||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.StatusLine;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.elasticsearch.client.Response;
|
||||
|
||||
@Singleton
|
||||
class ElasticIndexVersionDiscovery {
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
private final ElasticRestClientProvider client;
|
||||
|
||||
@Inject
|
||||
|
@ -37,17 +40,27 @@ class ElasticIndexVersionDiscovery {
|
|||
|
||||
List<String> discover(String prefix, String indexName) throws IOException {
|
||||
String name = prefix + indexName + "_";
|
||||
Response response = client.get().performRequest(HttpGet.METHOD_NAME, name + "*/_aliases");
|
||||
Response response =
|
||||
client
|
||||
.get()
|
||||
.performRequest(HttpGet.METHOD_NAME, client.adapter().getVersionDiscoveryUrl(name));
|
||||
|
||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
||||
return new JsonParser()
|
||||
.parse(AbstractElasticIndex.getContent(response))
|
||||
.getAsJsonObject()
|
||||
.entrySet()
|
||||
.stream()
|
||||
.map(e -> e.getKey().replace(name, ""))
|
||||
.collect(toList());
|
||||
StatusLine statusLine = response.getStatusLine();
|
||||
if (statusLine.getStatusCode() != HttpStatus.SC_OK) {
|
||||
String message =
|
||||
String.format(
|
||||
"Failed to discover index versions for %s: %d: %s",
|
||||
name, statusLine.getStatusCode(), statusLine.getReasonPhrase());
|
||||
logger.atSevere().log(message);
|
||||
throw new IOException(message);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
|
||||
return new JsonParser()
|
||||
.parse(AbstractElasticIndex.getContent(response))
|
||||
.getAsJsonObject()
|
||||
.entrySet()
|
||||
.stream()
|
||||
.map(e -> e.getKey().replace(name, ""))
|
||||
.collect(toList());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import com.google.inject.Inject;
|
|||
import com.google.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
|
@ -57,7 +58,9 @@ public class ElasticIndexVersionManager extends VersionManager {
|
|||
IndexDefinition<K, V, I> def, GerritIndexStatus cfg) {
|
||||
TreeMap<Integer, Version<V>> versions = new TreeMap<>();
|
||||
try {
|
||||
for (String version : versionDiscovery.discover(prefix, def.getName())) {
|
||||
List<String> discovered = versionDiscovery.discover(prefix, def.getName());
|
||||
logger.atFine().log("Discovered versions for %s: %s", def.getName(), discovered);
|
||||
for (String version : discovered) {
|
||||
Integer v = Ints.tryParse(version);
|
||||
if (v == null || version.length() != 4) {
|
||||
logger.atWarning().log("Unrecognized version in index %s: %s", def.getName(), version);
|
||||
|
|
|
@ -28,11 +28,14 @@ public class ElasticQueryAdapter {
|
|||
private final String stringFieldType;
|
||||
private final String indexProperty;
|
||||
private final String rawFieldsKey;
|
||||
private final String versionDiscoveryUrl;
|
||||
|
||||
ElasticQueryAdapter(ElasticVersion version) {
|
||||
this.ignoreUnmapped = version == ElasticVersion.V2_4;
|
||||
this.usePostV5Type = version == ElasticVersion.V6_2;
|
||||
|
||||
this.versionDiscoveryUrl = version == ElasticVersion.V6_2 ? "%s*" : "%s*/_aliases";
|
||||
|
||||
switch (version) {
|
||||
case V5_6:
|
||||
case V6_2:
|
||||
|
@ -98,4 +101,8 @@ public class ElasticQueryAdapter {
|
|||
String getType(String preV6Type) {
|
||||
return usePostV5Type() ? POST_V5_TYPE : preV6Type;
|
||||
}
|
||||
|
||||
String getVersionDiscoveryUrl(String name) {
|
||||
return String.format(versionDiscoveryUrl, name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1353,6 +1353,11 @@ public class ProjectConfig extends VersionedMetaData implements ValidationError.
|
|||
values.add(value.format().trim());
|
||||
}
|
||||
rc.setStringList(LABEL, name, KEY_VALUE, values);
|
||||
|
||||
List<String> refPatterns = label.getRefPatterns();
|
||||
if (refPatterns != null && !refPatterns.isEmpty()) {
|
||||
rc.setStringList(LABEL, name, KEY_BRANCH, refPatterns);
|
||||
}
|
||||
}
|
||||
|
||||
for (String name : toUnset) {
|
||||
|
|
|
@ -43,8 +43,10 @@ import com.google.gerrit.extensions.registration.RegistrationHandle;
|
|||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.server.group.SystemGroupBackend;
|
||||
import com.google.gerrit.server.project.ProjectConfig;
|
||||
import com.google.gerrit.server.project.testing.Util;
|
||||
import com.google.inject.Inject;
|
||||
import java.util.Arrays;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -334,6 +336,14 @@ public class CustomLabelIT extends AbstractDaemonTest {
|
|||
gApi.changes().id(changeId).current().submit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customLabel_withBranch() throws Exception {
|
||||
label.setRefPatterns(Arrays.asList("master"));
|
||||
saveLabelConfig();
|
||||
ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
|
||||
assertThat(cfg.getLabelSections().get(label.getName()).getRefPatterns()).contains("master");
|
||||
}
|
||||
|
||||
private void assertLabelStatus(String changeId, String testLabel) throws Exception {
|
||||
ChangeInfo changeInfo = getWithLabels(changeId);
|
||||
LabelInfo labelInfo = changeInfo.labels.get(testLabel);
|
||||
|
|
|
@ -45,20 +45,24 @@ public abstract class AbstractIndexTests extends AbstractDaemonTest {
|
|||
disableChangeIndexWrites();
|
||||
amendChange(changeId, "second test", "test2.txt", "test2");
|
||||
|
||||
assertQuery("message:second", change.getChange(), false);
|
||||
assertChangeQuery("message:second", change.getChange(), false);
|
||||
enableChangeIndexWrites();
|
||||
|
||||
String cmd = Joiner.on(" ").join("gerrit", "index", "changes", changeLegacyId);
|
||||
adminSshSession.exec(cmd);
|
||||
|
||||
assertQuery("message:second", change.getChange(), true);
|
||||
assertChangeQuery("message:second", change.getChange(), true);
|
||||
}
|
||||
|
||||
protected void assertQuery(String q, ChangeData change, Boolean assertTrue) throws Exception {
|
||||
protected void assertChangeQuery(String q, ChangeData change, Boolean assertTrue)
|
||||
throws Exception {
|
||||
List<ChangeInfo> result = query(q);
|
||||
Iterable<Integer> ids = ids(result);
|
||||
if (assertTrue) assertThat(ids).contains(change.getId().get());
|
||||
else assertThat(ids).doesNotContain(change.getId().get());
|
||||
if (assertTrue) {
|
||||
assertThat(ids).contains(change.getId().get());
|
||||
} else {
|
||||
assertThat(ids).doesNotContain(change.getId().get());
|
||||
}
|
||||
}
|
||||
|
||||
protected static Iterable<Integer> ids(Iterable<ChangeInfo> changes) {
|
||||
|
|
|
@ -28,12 +28,8 @@ public class ElasticIndexIT extends AbstractIndexTests {
|
|||
|
||||
private static Config getConfig(ElasticVersion version) {
|
||||
ElasticNodeInfo elasticNodeInfo;
|
||||
try {
|
||||
container = ElasticContainer.createAndStart(version);
|
||||
elasticNodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
|
||||
} catch (Throwable t) {
|
||||
return null;
|
||||
}
|
||||
container = ElasticContainer.createAndStart(version);
|
||||
elasticNodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
|
||||
String indicesPrefix = UUID.randomUUID().toString();
|
||||
Config cfg = new Config();
|
||||
ElasticTestUtils.configure(cfg, elasticNodeInfo.port, indicesPrefix);
|
||||
|
|
|
@ -155,7 +155,7 @@ limitations under the License.
|
|||
<gr-account-list
|
||||
max-count="1"
|
||||
id="assigneeValue"
|
||||
placeholder="Add assignee..."
|
||||
placeholder="Set assignee..."
|
||||
accounts="{{_assignee}}"
|
||||
change="[[change]]"
|
||||
readonly="[[_computeAssigneeReadOnly(mutable, change)]]"
|
||||
|
|
Loading…
Reference in New Issue