You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Indexers.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2024 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.server.es;
  21. import java.util.Collection;
  22. import java.util.stream.Collectors;
  23. import org.sonar.db.DbSession;
  24. import org.sonar.db.component.BranchDto;
  25. import org.sonar.db.entity.EntityDto;
  26. public interface Indexers {
  27. enum EntityEvent {
  28. CREATION,
  29. DELETION,
  30. PROJECT_KEY_UPDATE,
  31. PROJECT_TAGS_UPDATE,
  32. PERMISSION_CHANGE
  33. }
  34. enum BranchEvent {
  35. // Note that when a project/app is deleted, no events are sent for each branch removed as part of that process
  36. DELETION,
  37. MEASURE_CHANGE,
  38. SWITCH_OF_MAIN_BRANCH
  39. }
  40. /**
  41. * Re-index data based on the event. It commits the DB session once any indexing request was written in the same session,
  42. * ensuring consistency between the DB and the indexes. Therefore, DB data changes that cause the indexing event should
  43. * be done using the same DB session and the session should be uncommitted.
  44. */
  45. void commitAndIndexOnEntityEvent(DbSession dbSession, Collection<String> entityUuids, EntityEvent cause);
  46. /**
  47. * Re-index data based on the event. It commits the DB session once any indexing request was written in the same session,
  48. * ensuring consistency between the DB and the indexes. Therefore, DB data changes that cause the indexing event should
  49. * be done using the same DB session and the session should be uncommitted.
  50. */
  51. void commitAndIndexOnBranchEvent(DbSession dbSession, Collection<String> branchUuids, BranchEvent cause);
  52. /**
  53. * Re-index data based on the event. It commits the DB session once any indexing request was written in the same session,
  54. * ensuring consistency between the DB and the indexes. Therefore, DB data changes that cause the indexing event should
  55. * be done using the same DB session and the session should be uncommitted.
  56. */
  57. default void commitAndIndexEntities(DbSession dbSession, Collection<? extends EntityDto> entities, EntityEvent cause) {
  58. Collection<String> entityUuids = entities.stream()
  59. .map(EntityDto::getUuid)
  60. .collect(Collectors.toSet());
  61. commitAndIndexOnEntityEvent(dbSession, entityUuids, cause);
  62. }
  63. /**
  64. * Re-index data based on the event. It commits the DB session once any indexing request was written in the same session,
  65. * ensuring consistency between the DB and the indexes. Therefore, DB data changes that cause the indexing event should
  66. * be done using the same DB session and the session should be uncommitted.
  67. */
  68. default void commitAndIndexBranches(DbSession dbSession, Collection<BranchDto> branches, BranchEvent cause) {
  69. Collection<String> branchUuids = branches.stream()
  70. .map(BranchDto::getUuid)
  71. .collect(Collectors.toSet());
  72. commitAndIndexOnBranchEvent(dbSession, branchUuids, cause);
  73. }
  74. }