diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2016-10-20 12:09:21 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2016-10-20 13:16:50 +0200 |
commit | 1ab2d1cc43df5a9af5944e0b8c946c11d34ed41c (patch) | |
tree | 0d366607ab3d4d5aaf61bfb7e309b1c54c5cde6e /server/sonar-server | |
parent | 384c1aa3aefde97b78413d621cfc9fa60a0484c9 (diff) | |
download | sonarqube-1ab2d1cc43df5a9af5944e0b8c946c11d34ed41c.tar.gz sonarqube-1ab2d1cc43df5a9af5944e0b8c946c11d34ed41c.zip |
SONAR-8227 Remove permission from index at the same time than removing a project from index
Diffstat (limited to 'server/sonar-server')
6 files changed, 19 insertions, 32 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentCleanerService.java b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentCleanerService.java index 7ad9b8305e8..375b6743727 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentCleanerService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentCleanerService.java @@ -29,9 +29,9 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.MyBatis; import org.sonar.db.component.ComponentDto; +import org.sonar.server.component.es.ProjectMeasuresIndexer; import org.sonar.server.issue.index.IssueIndexer; import org.sonar.server.permission.index.AuthorizationIndexer; -import org.sonar.server.component.es.ProjectMeasuresIndexer; import org.sonar.server.test.index.TestIndexer; @ServerSide @@ -84,8 +84,6 @@ public class ComponentCleanerService { } private void deleteFromIndices(String projectUuid) { - // optimization : index "issues" is refreshed once at the end - authorizationIndexer.deleteProject(projectUuid, false); issueIndexer.deleteProject(projectUuid); testIndexer.deleteByProject(projectUuid); projectMeasuresIndexer.deleteProject(projectUuid); diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/es/ProjectMeasuresIndexer.java b/server/sonar-server/src/main/java/org/sonar/server/component/es/ProjectMeasuresIndexer.java index f38c4588306..59da24cedfd 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/es/ProjectMeasuresIndexer.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/es/ProjectMeasuresIndexer.java @@ -32,6 +32,7 @@ import org.sonar.server.es.EsClient; import static org.sonar.server.component.es.ProjectMeasuresIndexDefinition.FIELD_ANALYSED_AT; import static org.sonar.server.component.es.ProjectMeasuresIndexDefinition.INDEX_PROJECT_MEASURES; +import static org.sonar.server.component.es.ProjectMeasuresIndexDefinition.TYPE_AUTHORIZATION; import static org.sonar.server.component.es.ProjectMeasuresIndexDefinition.TYPE_PROJECT_MEASURES; public class ProjectMeasuresIndexer extends BaseIndexer { @@ -58,6 +59,11 @@ public class ProjectMeasuresIndexer extends BaseIndexer { .setRouting(uuid) .setRefresh(true) .get(); + esClient + .prepareDelete(INDEX_PROJECT_MEASURES, TYPE_AUTHORIZATION, uuid) + .setRouting(uuid) + .setRefresh(true) + .get(); } private long doIndex(BulkIndexer bulk, long lastUpdatedAt, @Nullable String projectUuid) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/index/AuthorizationIndexer.java b/server/sonar-server/src/main/java/org/sonar/server/permission/index/AuthorizationIndexer.java index 7ed91cbc758..d2ebc57d28e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/index/AuthorizationIndexer.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/index/AuthorizationIndexer.java @@ -155,19 +155,6 @@ public class AuthorizationIndexer implements Startable { .get(); } - public void deleteProject(String uuid, boolean refresh) { - esClient - .prepareDelete(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_AUTHORIZATION, uuid) - .setRefresh(refresh) - .setRouting(uuid) - .get(); - esClient - .prepareDelete(ProjectMeasuresIndexDefinition.INDEX_PROJECT_MEASURES, ProjectMeasuresIndexDefinition.TYPE_AUTHORIZATION, uuid) - .setRefresh(refresh) - .setRouting(uuid) - .get(); - } - private static IndexRequest newIssuesAuthorizationIndexRequest(AuthorizationDao.Dto dto) { Map<String, Object> doc = ImmutableMap.of( IssueIndexDefinition.FIELD_AUTHORIZATION_PROJECT_UUID, dto.getProjectUuid(), diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentCleanerServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentCleanerServiceTest.java index d8d9ac3af8d..ede7d441018 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentCleanerServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentCleanerServiceTest.java @@ -250,11 +250,13 @@ public class ComponentCleanerServiceTest { assertThat(es.getIds(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_AUTHORIZATION)).contains(data.project.uuid()); assertThat(es.getIds(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE)).contains(data.testId); assertThat(es.getIds(ProjectMeasuresIndexDefinition.INDEX_PROJECT_MEASURES, ProjectMeasuresIndexDefinition.TYPE_PROJECT_MEASURES)).contains(data.project.uuid()); + assertThat(es.getIds(ProjectMeasuresIndexDefinition.INDEX_PROJECT_MEASURES, ProjectMeasuresIndexDefinition.TYPE_AUTHORIZATION)).contains(data.project.uuid()); } else { assertThat(es.getIds(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_ISSUE)).doesNotContain(data.issueKey); assertThat(es.getIds(IssueIndexDefinition.INDEX, IssueIndexDefinition.TYPE_AUTHORIZATION)).doesNotContain(data.project.uuid()); assertThat(es.getIds(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE)).doesNotContain(data.testId); assertThat(es.getIds(ProjectMeasuresIndexDefinition.INDEX_PROJECT_MEASURES, ProjectMeasuresIndexDefinition.TYPE_PROJECT_MEASURES)).doesNotContain(data.project.uuid()); + assertThat(es.getIds(ProjectMeasuresIndexDefinition.INDEX_PROJECT_MEASURES, ProjectMeasuresIndexDefinition.TYPE_AUTHORIZATION)).doesNotContain(data.project.uuid()); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/es/ProjectMeasuresIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/es/ProjectMeasuresIndexerTest.java index 6e050501228..aaf66fcc26c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/es/ProjectMeasuresIndexerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/es/ProjectMeasuresIndexerTest.java @@ -31,13 +31,16 @@ import org.sonar.db.component.ComponentDbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.SnapshotDto; import org.sonar.server.es.EsTester; +import org.sonar.server.permission.index.AuthorizationIndexerTester; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.elasticsearch.index.query.QueryBuilders.boolQuery; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; import static org.elasticsearch.index.query.QueryBuilders.termQuery; import static org.sonar.db.component.ComponentTesting.newProjectDto; import static org.sonar.server.component.es.ProjectMeasuresIndexDefinition.INDEX_PROJECT_MEASURES; +import static org.sonar.server.component.es.ProjectMeasuresIndexDefinition.TYPE_AUTHORIZATION; import static org.sonar.server.component.es.ProjectMeasuresIndexDefinition.TYPE_PROJECT_MEASURES; public class ProjectMeasuresIndexerTest { @@ -49,6 +52,7 @@ public class ProjectMeasuresIndexerTest { public DbTester dbTester = DbTester.create(System2.INSTANCE); ComponentDbTester componentDbTester = new ComponentDbTester(dbTester); + AuthorizationIndexerTester authorizationIndexerTester = new AuthorizationIndexerTester(esTester); ProjectMeasuresIndexer underTest = new ProjectMeasuresIndexer(dbTester.getDbClient(), esTester.client()); @@ -125,10 +129,14 @@ public class ProjectMeasuresIndexerTest { ComponentDto project3 = newProjectDto(); componentDbTester.insertProjectAndSnapshot(project3); underTest.index(); + authorizationIndexerTester.insertProjectAuthorization(project1.uuid(), emptyList(), emptyList()); + authorizationIndexerTester.insertProjectAuthorization(project2.uuid(), emptyList(), emptyList()); + authorizationIndexerTester.insertProjectAuthorization(project3.uuid(), emptyList(), emptyList()); underTest.deleteProject(project1.uuid()); assertThat(esTester.getIds(INDEX_PROJECT_MEASURES, TYPE_PROJECT_MEASURES)).containsOnly(project2.uuid(), project3.uuid()); + assertThat(esTester.getIds(INDEX_PROJECT_MEASURES, TYPE_AUTHORIZATION)).containsOnly(project2.uuid(), project3.uuid()); } @Test @@ -136,9 +144,11 @@ public class ProjectMeasuresIndexerTest { ComponentDto project = newProjectDto(); componentDbTester.insertProjectAndSnapshot(project); underTest.index(); + authorizationIndexerTester.insertProjectAuthorization(project.uuid(), emptyList(), emptyList()); underTest.deleteProject("UNKNOWN"); assertThat(esTester.getIds(INDEX_PROJECT_MEASURES, TYPE_PROJECT_MEASURES)).containsOnly(project.uuid()); + assertThat(esTester.getIds(INDEX_PROJECT_MEASURES, TYPE_AUTHORIZATION)).containsOnly(project.uuid()); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/index/AuthorizationIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/index/AuthorizationIndexerTest.java index 8fa2c0400d1..1e5fcae3e18 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/permission/index/AuthorizationIndexerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/permission/index/AuthorizationIndexerTest.java @@ -158,22 +158,6 @@ public class AuthorizationIndexerTest { } @Test - public void delete_project() { - authorizationIndexerTester.insertProjectAuthorization("ABC", singletonList("guy"), singletonList("dev")); - - underTest.deleteProject("ABC", true); - - authorizationIndexerTester.verifyEmptyProjectAuthorization(); - } - - @Test - public void do_not_fail_when_deleting_unknown_project() { - underTest.deleteProject("UNKNOWN", true); - - authorizationIndexerTester.verifyEmptyProjectAuthorization(); - } - - @Test public void update_existing_permissions() { authorizationIndexerTester.insertProjectAuthorization("ABC", singletonList("guy"), singletonList("dev")); |