Skip to content

Commit

Permalink
SONAR-8888 fix indexing of quality profiles on SQLServer
Browse files Browse the repository at this point in the history
When creating an organization, Elasticsearch index rules/active_rule
must be updated only when DB session is committed, otherwise
the DB session of ActiveRuleIndexer is locked by the DB
session of OrganizationCreationImpl.
  • Loading branch information
Simon Brandhof authored and sns-seb committed Mar 23, 2017
1 parent df6b7d4 commit ba3fc02
Showing 1 changed file with 10 additions and 4 deletions.
Expand Up @@ -95,11 +95,14 @@ public OrganizationDto create(DbSession dbSession, int creatorUserId, NewOrganiz
insertOrganizationMember(dbSession, organization, creatorUserId);
GroupDto group = insertOwnersGroup(dbSession, organization);
insertDefaultTemplate(dbSession, organization, group);
insertQualityProfiles(dbSession, organization);
List<ActiveRuleChange> activeRuleChanges = insertQualityProfiles(dbSession, organization);
addCurrentUserToGroup(dbSession, group, creatorUserId);

dbSession.commit();

// Elasticsearch is updated when DB session is committed
activeRuleIndexer.index(activeRuleChanges);

return organization;
}

Expand All @@ -126,10 +129,13 @@ public Optional<OrganizationDto> createForUser(DbSession dbSession, UserDto newU
.forEach(p -> insertUserPermissions(dbSession, newUser, organization, p));
insertPersonalOrgDefaultTemplate(dbSession, organization);
insertOrganizationMember(dbSession, organization, newUser.getId());
insertQualityProfiles(dbSession, organization);
List<ActiveRuleChange> activeRuleChanges = insertQualityProfiles(dbSession, organization);

dbSession.commit();

// Elasticsearch is updated when DB session is committed
activeRuleIndexer.index(activeRuleChanges);

return Optional.of(organization);
}

Expand Down Expand Up @@ -242,13 +248,13 @@ private void insertGroupPermission(DbSession dbSession, PermissionTemplateDto te
dbClient.permissionTemplateDao().insertGroupPermission(dbSession, template.getId(), group == null ? null : group.getId(), permission);
}

private void insertQualityProfiles(DbSession dbSession, OrganizationDto organization) {
private List<ActiveRuleChange> insertQualityProfiles(DbSession dbSession, OrganizationDto organization) {
List<ActiveRuleChange> changes = new ArrayList<>();
definedQProfileRepository.getQProfilesByLanguage().entrySet()
.stream()
.flatMap(entry -> entry.getValue().stream())
.forEach(profile -> insertQualityProfile(dbSession, profile, organization, changes));
activeRuleIndexer.index(changes);
return changes;
}

private void insertQualityProfile(DbSession dbSession, DefinedQProfile profile, OrganizationDto organization, List<ActiveRuleChange> changes) {
Expand Down

0 comments on commit ba3fc02

Please sign in to comment.