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:
David Pursehouse 2018-06-18 09:34:35 +09:00
commit 0bfe395b3b
9 changed files with 64 additions and 26 deletions

View File

@ -924,8 +924,8 @@ maven_jar(
maven_jar( maven_jar(
name = "testcontainers", name = "testcontainers",
artifact = "org.testcontainers:testcontainers:1.7.2", artifact = "org.testcontainers:testcontainers:1.8.0",
sha1 = "fec8b360b6b613f6c9d3b8e7a9fa32d1a2bcb978", sha1 = "bc413912f7044f9f12aa0782853aef0a067ee52a",
) )
maven_jar( maven_jar(

View File

@ -16,18 +16,21 @@ package com.google.gerrit.elasticsearch;
import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toList;
import com.google.common.flogger.FluentLogger;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.elasticsearch.client.Response; import org.elasticsearch.client.Response;
@Singleton @Singleton
class ElasticIndexVersionDiscovery { class ElasticIndexVersionDiscovery {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final ElasticRestClientProvider client; private final ElasticRestClientProvider client;
@Inject @Inject
@ -37,17 +40,27 @@ class ElasticIndexVersionDiscovery {
List<String> discover(String prefix, String indexName) throws IOException { List<String> discover(String prefix, String indexName) throws IOException {
String name = prefix + indexName + "_"; 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) { StatusLine statusLine = response.getStatusLine();
return new JsonParser() if (statusLine.getStatusCode() != HttpStatus.SC_OK) {
.parse(AbstractElasticIndex.getContent(response)) String message =
.getAsJsonObject() String.format(
.entrySet() "Failed to discover index versions for %s: %d: %s",
.stream() name, statusLine.getStatusCode(), statusLine.getReasonPhrase());
.map(e -> e.getKey().replace(name, "")) logger.atSevere().log(message);
.collect(toList()); 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());
} }
} }

View File

@ -30,6 +30,7 @@ import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import java.util.TreeMap; import java.util.TreeMap;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
@ -57,7 +58,9 @@ public class ElasticIndexVersionManager extends VersionManager {
IndexDefinition<K, V, I> def, GerritIndexStatus cfg) { IndexDefinition<K, V, I> def, GerritIndexStatus cfg) {
TreeMap<Integer, Version<V>> versions = new TreeMap<>(); TreeMap<Integer, Version<V>> versions = new TreeMap<>();
try { 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); Integer v = Ints.tryParse(version);
if (v == null || version.length() != 4) { if (v == null || version.length() != 4) {
logger.atWarning().log("Unrecognized version in index %s: %s", def.getName(), version); logger.atWarning().log("Unrecognized version in index %s: %s", def.getName(), version);

View File

@ -28,11 +28,14 @@ public class ElasticQueryAdapter {
private final String stringFieldType; private final String stringFieldType;
private final String indexProperty; private final String indexProperty;
private final String rawFieldsKey; private final String rawFieldsKey;
private final String versionDiscoveryUrl;
ElasticQueryAdapter(ElasticVersion version) { ElasticQueryAdapter(ElasticVersion version) {
this.ignoreUnmapped = version == ElasticVersion.V2_4; this.ignoreUnmapped = version == ElasticVersion.V2_4;
this.usePostV5Type = version == ElasticVersion.V6_2; this.usePostV5Type = version == ElasticVersion.V6_2;
this.versionDiscoveryUrl = version == ElasticVersion.V6_2 ? "%s*" : "%s*/_aliases";
switch (version) { switch (version) {
case V5_6: case V5_6:
case V6_2: case V6_2:
@ -98,4 +101,8 @@ public class ElasticQueryAdapter {
String getType(String preV6Type) { String getType(String preV6Type) {
return usePostV5Type() ? POST_V5_TYPE : preV6Type; return usePostV5Type() ? POST_V5_TYPE : preV6Type;
} }
String getVersionDiscoveryUrl(String name) {
return String.format(versionDiscoveryUrl, name);
}
} }

View File

@ -1353,6 +1353,11 @@ public class ProjectConfig extends VersionedMetaData implements ValidationError.
values.add(value.format().trim()); values.add(value.format().trim());
} }
rc.setStringList(LABEL, name, KEY_VALUE, values); 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) { for (String name : toUnset) {

View File

@ -43,8 +43,10 @@ import com.google.gerrit.extensions.registration.RegistrationHandle;
import com.google.gerrit.extensions.restapi.ResourceConflictException; import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.reviewdb.client.AccountGroup; import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.server.group.SystemGroupBackend; 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.gerrit.server.project.testing.Util;
import com.google.inject.Inject; import com.google.inject.Inject;
import java.util.Arrays;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -334,6 +336,14 @@ public class CustomLabelIT extends AbstractDaemonTest {
gApi.changes().id(changeId).current().submit(); 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 { private void assertLabelStatus(String changeId, String testLabel) throws Exception {
ChangeInfo changeInfo = getWithLabels(changeId); ChangeInfo changeInfo = getWithLabels(changeId);
LabelInfo labelInfo = changeInfo.labels.get(testLabel); LabelInfo labelInfo = changeInfo.labels.get(testLabel);

View File

@ -45,20 +45,24 @@ public abstract class AbstractIndexTests extends AbstractDaemonTest {
disableChangeIndexWrites(); disableChangeIndexWrites();
amendChange(changeId, "second test", "test2.txt", "test2"); amendChange(changeId, "second test", "test2.txt", "test2");
assertQuery("message:second", change.getChange(), false); assertChangeQuery("message:second", change.getChange(), false);
enableChangeIndexWrites(); enableChangeIndexWrites();
String cmd = Joiner.on(" ").join("gerrit", "index", "changes", changeLegacyId); String cmd = Joiner.on(" ").join("gerrit", "index", "changes", changeLegacyId);
adminSshSession.exec(cmd); 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); List<ChangeInfo> result = query(q);
Iterable<Integer> ids = ids(result); Iterable<Integer> ids = ids(result);
if (assertTrue) assertThat(ids).contains(change.getId().get()); if (assertTrue) {
else assertThat(ids).doesNotContain(change.getId().get()); assertThat(ids).contains(change.getId().get());
} else {
assertThat(ids).doesNotContain(change.getId().get());
}
} }
protected static Iterable<Integer> ids(Iterable<ChangeInfo> changes) { protected static Iterable<Integer> ids(Iterable<ChangeInfo> changes) {

View File

@ -28,12 +28,8 @@ public class ElasticIndexIT extends AbstractIndexTests {
private static Config getConfig(ElasticVersion version) { private static Config getConfig(ElasticVersion version) {
ElasticNodeInfo elasticNodeInfo; ElasticNodeInfo elasticNodeInfo;
try { container = ElasticContainer.createAndStart(version);
container = ElasticContainer.createAndStart(version); elasticNodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
elasticNodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
} catch (Throwable t) {
return null;
}
String indicesPrefix = UUID.randomUUID().toString(); String indicesPrefix = UUID.randomUUID().toString();
Config cfg = new Config(); Config cfg = new Config();
ElasticTestUtils.configure(cfg, elasticNodeInfo.port, indicesPrefix); ElasticTestUtils.configure(cfg, elasticNodeInfo.port, indicesPrefix);

View File

@ -155,7 +155,7 @@ limitations under the License.
<gr-account-list <gr-account-list
max-count="1" max-count="1"
id="assigneeValue" id="assigneeValue"
placeholder="Add assignee..." placeholder="Set assignee..."
accounts="{{_assignee}}" accounts="{{_assignee}}"
change="[[change]]" change="[[change]]"
readonly="[[_computeAssigneeReadOnly(mutable, change)]]" readonly="[[_computeAssigneeReadOnly(mutable, change)]]"