use of com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo in project gerrit by GerritCodeReview.
the class ExternalIdsConsistencyChecker method check.
private List<ConsistencyProblemInfo> check(ExternalIdNotes extIdNotes) throws IOException {
List<ConsistencyProblemInfo> problems = new ArrayList<>();
ListMultimap<String, ExternalId> emails = MultimapBuilder.hashKeys().arrayListValues().build();
try (RevWalk rw = new RevWalk(extIdNotes.getRepository())) {
NoteMap noteMap = extIdNotes.getNoteMap();
for (Note note : noteMap) {
byte[] raw = ExternalIdNotes.readNoteData(rw, note.getData());
try {
ExternalId extId = externalIdFactory.parse(note.getName(), raw, note.getData());
problems.addAll(validateExternalId(extId));
if (extId.email() != null) {
String email = extId.email();
if (emails.get(email).stream().noneMatch(e -> e.accountId().get() == extId.accountId().get())) {
emails.put(email, extId);
}
}
} catch (ConfigInvalidException e) {
addError(String.format(e.getMessage()), problems);
}
}
}
emails.asMap().entrySet().stream().filter(e -> e.getValue().size() > 1).forEach(e -> addError(String.format("Email '%s' is not unique, it's used by the following external IDs: %s", e.getKey(), e.getValue().stream().map(k -> "'" + k.key().get() + "'").sorted().collect(joining(", "))), problems));
return problems;
}
use of com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo in project gerrit by GerritCodeReview.
the class ExternalIdIT method insertNonParsableExternalIds.
private Set<ConsistencyProblemInfo> insertNonParsableExternalIds() throws IOException {
MutableInteger i = new MutableInteger();
String scheme = "corrupt";
Set<ConsistencyProblemInfo> expectedProblems = new HashSet<>();
try (Repository repo = repoManager.openRepository(allUsers);
RevWalk rw = new RevWalk(repo)) {
String externalId = nextId(scheme, i);
String noteId = insertExternalIdWithoutAccountId(repo, rw, admin.newIdent(), admin.id(), externalId);
expectedProblems.add(consistencyError("Invalid external ID config for note '" + noteId + "': Value for 'externalId." + externalId + ".accountId' is missing, expected account ID"));
externalId = nextId(scheme, i);
noteId = insertExternalIdWithKeyThatDoesntMatchNoteId(repo, rw, admin.newIdent(), admin.id(), externalId);
expectedProblems.add(consistencyError("Invalid external ID config for note '" + noteId + "': SHA1 of external ID '" + externalId + "' does not match note ID '" + noteId + "'"));
noteId = insertExternalIdWithInvalidConfig(repo, rw, admin.newIdent(), nextId(scheme, i));
expectedProblems.add(consistencyError("Invalid external ID config for note '" + noteId + "': Invalid line in config file"));
noteId = insertExternalIdWithEmptyNote(repo, rw, admin.newIdent(), nextId(scheme, i));
expectedProblems.add(consistencyError("Invalid external ID config for note '" + noteId + "': Expected exactly 1 'externalId' section, found 0"));
}
return expectedProblems;
}
use of com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo in project gerrit by GerritCodeReview.
the class GroupsNoteDbConsistencyChecker method checkGlobalConsistency.
/**
* Check invariants of the group refs with the group name refs.
*/
private List<ConsistencyProblemInfo> checkGlobalConsistency(Map<AccountGroup.UUID, InternalGroup> uuidToGroupMap, BiMap<AccountGroup.UUID, String> uuidNameBiMap) {
List<ConsistencyProblemInfo> problems = new ArrayList<>();
// Check consistency between the data coming from different refs.
for (AccountGroup.UUID uuid : uuidToGroupMap.keySet()) {
if (!uuidNameBiMap.containsKey(uuid)) {
problems.add(error("group %s has no entry in name map", uuid));
continue;
}
String noteName = uuidNameBiMap.get(uuid);
String groupRefName = uuidToGroupMap.get(uuid).getName();
if (!Objects.equals(noteName, groupRefName)) {
problems.add(error("inconsistent name for group %s (name map %s vs. group ref %s)", uuid, noteName, groupRefName));
}
}
for (AccountGroup.UUID uuid : uuidNameBiMap.keySet()) {
if (!uuidToGroupMap.containsKey(uuid)) {
problems.add(error("name map has entry (%s, %s), entry missing as group ref", uuid, uuidNameBiMap.get(uuid)));
}
}
if (problems.isEmpty()) {
// Check ids.
Map<AccountGroup.Id, InternalGroup> groupById = new HashMap<>();
for (InternalGroup g : uuidToGroupMap.values()) {
InternalGroup before = groupById.get(g.getId());
if (before != null) {
problems.add(error("shared group id %s for %s (%s) and %s (%s)", g.getId(), before.getName(), before.getGroupUUID(), g.getName(), g.getGroupUUID()));
}
groupById.put(g.getId(), g);
}
}
return problems;
}
use of com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo in project gerrit by GerritCodeReview.
the class ExternalIdsConsistencyChecker method check.
private List<ConsistencyProblemInfo> check(Repository repo, ObjectId commit) throws IOException {
List<ConsistencyProblemInfo> problems = new ArrayList<>();
ListMultimap<String, ExternalId.Key> emails = MultimapBuilder.hashKeys().arrayListValues().build();
try (RevWalk rw = new RevWalk(repo)) {
NoteMap noteMap = ExternalIdReader.readNoteMap(rw, commit);
for (Note note : noteMap) {
byte[] raw = rw.getObjectReader().open(note.getData(), OBJ_BLOB).getCachedBytes(ExternalIdReader.MAX_NOTE_SZ);
try {
ExternalId extId = ExternalId.parse(note.getName(), raw);
problems.addAll(validateExternalId(extId));
if (extId.email() != null) {
emails.put(extId.email(), extId.key());
}
} catch (ConfigInvalidException e) {
addError(String.format(e.getMessage()), problems);
}
}
}
emails.asMap().entrySet().stream().filter(e -> e.getValue().size() > 1).forEach(e -> addError(String.format("Email '%s' is not unique, it's used by the following external IDs: %s", e.getKey(), e.getValue().stream().map(k -> "'" + k.get() + "'").sorted().collect(joining(", "))), problems));
return problems;
}
use of com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo in project gerrit by GerritCodeReview.
the class GroupsConsistencyChecker method checkCycle.
/**
* checkCycle walks through root's subgroups recursively, and checks for cycles.
*/
private List<ConsistencyProblemInfo> checkCycle(InternalGroup root, Map<AccountGroup.UUID, InternalGroup> byUUID) {
List<ConsistencyProblemInfo> problems = new ArrayList<>();
Set<InternalGroup> todo = new LinkedHashSet<>();
Set<InternalGroup> seen = new HashSet<>();
todo.add(root);
while (!todo.isEmpty()) {
InternalGroup t = todo.iterator().next();
todo.remove(t);
if (seen.contains(t)) {
continue;
}
seen.add(t);
// We don't check for owner cycles, since those are normal in self-administered groups.
for (AccountGroup.UUID subUuid : t.getSubgroups()) {
InternalGroup g = byUUID.get(subUuid);
if (g == null) {
continue;
}
if (Objects.equals(g, root)) {
problems.add(warning("group %s (%s) contains a cycle: %s (%s) points to it as subgroup.", root.getName(), root.getGroupUUID(), t.getName(), t.getGroupUUID()));
}
todo.add(g);
}
}
return problems;
}
Aggregations