import java.util.Map;
/**
- * Manages the synchronization of index issues/issueAuthorization with authorization settings defined in database :
+ * Manages the synchronization of index issues/authorization with authorization settings defined in database :
* <ul>
* <li>index the projects with recent permission changes</li>
* <li>delete project orphans from index</li>
public static final String INDEX = "issues";
- public static final String TYPE_AUTHORIZATION = "issueAuthorization";
+ public static final String TYPE_AUTHORIZATION = "authorization";
public static final String TYPE_ISSUE = "issue";
public static final String FIELD_AUTHORIZATION_PROJECT_UUID = "project";
// else keep defaults (one shard)
}
- // type "issueAuthorization"
+ // type "authorization"
NewIndex.NewIndexType authorizationMapping = index.createType(TYPE_AUTHORIZATION);
authorizationMapping.setAttribute("_id", ImmutableMap.of("path", FIELD_AUTHORIZATION_PROJECT_UUID));
authorizationMapping.createDateTimeField(FIELD_AUTHORIZATION_UPDATED_AT);
private UpdateRequest newUpsertRequest(IssueDoc issue) {
String projectUuid = issue.projectUuid();
- // parent doc is issueAuthorization
+ // type of parent doc is "authorization"
issue.setField("_parent", projectUuid);
return new UpdateRequest(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE, issue.key())
public static final IndexDefinition RULE = new IndexDefinition("rules", "rule");
public static final IndexDefinition ACTIVE_RULE = new IndexDefinition("rules", "activeRule");
- public static final IndexDefinition ISSUES_AUTHORIZATION = new IndexDefinition("issues", "issueAuthorization");
public static final IndexDefinition ISSUES = new IndexDefinition("issues", "issue");
public static final IndexDefinition LOG = new IndexDefinition("logs", "sonarLog");
/* synchronize all activeRules until we have mng tables in INDEX */
DbSession session = db.openSession(true);
try {
- LOG.info("Starting DB to Index synchronization");
- long start = System.currentTimeMillis();
List<String> projectUuids = db.componentDao().findProjectUuids(session);
synchronize(session, db.ruleDao(), index.get(RuleIndex.class));
issueAuthorizationIndexer.index();
sourceLineIndexer.index();
session.commit();
- LOG.info("Synchronization done in {}ms...", System.currentTimeMillis() - start);
} finally {
session.close();
}
IssueAuthorizationIndexer indexer = createIndexer();
indexer.doIndex(0L);
- assertThat(esTester.countDocuments("issues", "issueAuthorization")).isZero();
+ assertThat(esTester.countDocuments("issues", "authorization")).isZero();
}
@Test
IssueAuthorizationIndexer indexer = createIndexer();
indexer.doIndex(0L);
- List<SearchHit> docs = esTester.getDocuments("issues", "issueAuthorization");
+ List<SearchHit> docs = esTester.getDocuments("issues", "authorization");
assertThat(docs).hasSize(1);
SearchHit doc = docs.get(0);
assertThat(doc.getSource().get("project")).isEqualTo("ABC");
public void do_not_fail_when_deleting_unindexed_project() throws Exception {
IssueAuthorizationIndexer indexer = createIndexer();
indexer.deleteProject("UNKNOWN", true);
- assertThat(esTester.countDocuments("issues", "issueAuthorization")).isZero();
+ assertThat(esTester.countDocuments("issues", "authorization")).isZero();
}
@Test
indexer.index(Arrays.asList(authorization));
// has permissions
- assertThat(esTester.countDocuments("issues", "issueAuthorization")).isEqualTo(1);
+ assertThat(esTester.countDocuments("issues", "authorization")).isEqualTo(1);
// remove permissions -> dto has no users nor groups
authorization = new IssueAuthorizationDao.Dto("ABC", System.currentTimeMillis());
indexer.index(Arrays.asList(authorization));
- assertThat(esTester.countDocuments("issues", "issueAuthorization")).isZero();
+ assertThat(esTester.countDocuments("issues", "authorization")).isZero();
}
private IssueAuthorizationIndexer createIndexer() {
assertThat(context.getIndices()).hasSize(1);
NewIndex issuesIndex = context.getIndices().get("issues");
assertThat(issuesIndex).isNotNull();
- assertThat(issuesIndex.getTypes().keySet()).containsOnly("issue", "issueAuthorization");
+ assertThat(issuesIndex.getTypes().keySet()).containsOnly("issue", "authorization");
// no cluster by default
assertThat(issuesIndex.getSettings().get("index.number_of_shards")).isEqualTo("1");